- How do I install **tc-lib-pdf-encrypt** in a Laravel project?
- Run `composer require tecnickcom/tc-lib-pdf-encrypt` in your project directory. Ensure PHP 7.4+ is installed, as the package requires it. No Laravel-specific dependencies are needed, but it works best alongside TCPDF or similar libraries for PDF generation.
- Does this package support **AES-256 encryption** for PDFs?
- The package implements standard PDF encryption routines, including password-based protection, but it does not explicitly guarantee AES-256. It primarily relies on TCPDF’s underlying encryption methods, which may use RC4 or other legacy algorithms. For AES-256, consider alternatives like OpenSSL or commercial libraries.
- Can I use this with **Laravel DomPDF** or **Spatie PDF**?
- Yes, but indirectly. Since this library focuses on post-processing PDFs, you’d generate the PDF first (e.g., with DomPDF or Spatie) and then pass it to `tc-lib-pdf-encrypt` for encryption. It’s not a direct integration but works as a service layer for securing existing PDFs.
- What **Laravel versions** does this package support?
- The package itself doesn’t enforce Laravel version constraints, but it requires PHP 7.4+. Test compatibility with your Laravel version (e.g., 8.x, 9.x) by verifying TCPDF or TC-Lib dependencies, as this library extends those ecosystems. No Laravel-specific features are provided.
- How do I set **permissions** (e.g., disable printing) for encrypted PDFs?
- Use the library’s methods to define access flags, such as restricting printing or copying. For example, `encryptFile($path, $password, $permissions)` where `$permissions` is a bitmask (e.g., `16` for no printing). Refer to the TCPDF documentation for valid permission values.
- Is this package **secure enough for HIPAA/GDPR compliance**?
- While it provides basic PDF encryption, compliance depends on your implementation. The library doesn’t guarantee FIPS 140-2 or NIST standards. For regulated environments, use dedicated tools like OpenSSL or commercial libraries (e.g., iText) and combine with Laravel’s encryption services for end-to-end security.
- How do I handle **encryption keys** in Laravel (e.g., environment variables)?
- Store passwords or keys in Laravel’s `.env` file or use the `config()` helper. Avoid hardcoding keys. For dynamic keys, integrate with Laravel Vault or a dedicated secrets manager. The library itself doesn’t enforce key storage—you’ll need to pass the password/key during encryption.
- Will this work with **large PDFs** (e.g., 100MB+)?
- Performance may degrade with large files due to PHP’s memory limits and the library’s I/O operations. Test with your expected file sizes and monitor memory usage. For high-throughput apps, consider async processing (e.g., Laravel Queues) or offloading encryption to a microservice.
- Are there **alternatives** to this package for Laravel PDF encryption?
- Yes. For lightweight needs, use OpenSSL’s `openssl_pkcs7_encrypt()` or Laravel’s built-in `encrypt()`. For advanced PDFs, try Ghostscript + OpenSSL or commercial libraries like iText. If you’re using DomPDF/Spatie, check their encryption extensions or post-process with `pdftk` via Symfony Process.
- How do I **test** PDF encryption in Laravel (unit/feature tests)?
- Mock the library’s encryption methods in PHPUnit to avoid file I/O. Test edge cases like invalid passwords or corrupt PDFs. Use Laravel’s `Storage` facade to simulate file paths. For integration tests, generate a PDF (e.g., with Spatie), encrypt it, and verify the output with a PDF validator like `pdfinfo` from Ghostscript.