- How do I merge multiple PDFs into one file using this package?
- Use the `PdfManager::merge()` method, passing an array of file paths or storage disk references. For example, `PdfManager::merge(['file1.pdf', 'file2.pdf'])->saveAs('merged.pdf')`. Ensure files are accessible via Laravel’s filesystem or absolute paths. The method returns a `Pdf` object for further manipulation or direct saving.
- Does this package support splitting PDFs into individual pages or ranges?
- Yes, call `PdfManager::split('input.pdf', [1, 3])` to extract pages 1 and 3 as separate files. You can also split into ranges (e.g., `split('input.pdf', [1, 5])` for pages 1–5). The package returns an array of temporary file paths or `Pdf` objects, which you can save or stream directly.
- What Laravel versions does **docdigital/pdf-manager** support?
- The package is designed for Laravel 8.x and 9.x, leveraging modern PHP features like named arguments and attributes. Check the repository’s `composer.json` for the exact PHP version requirement (typically 8.0+). If using Laravel 10+, verify compatibility with the underlying PDF library (FPDF/TCPDF) for potential deprecations.
- Can I offload PDF merging/splitting to a queue to avoid timeouts?
- Yes, wrap operations in a Laravel job (e.g., `MergePdfJob`) and dispatch them to a queue. The package itself doesn’t enforce async, but you can integrate it with Laravel Queues or Horizon. For large files, ensure your queue worker has sufficient memory (e.g., `php.ini` `memory_limit` or `queue:work --memory=512M`).
- How do I handle large PDFs (e.g., 100MB+) without memory issues?
- Process files in chunks or stream them directly to disk using `PdfManager::merge()->streamToDisk()`. For splitting, specify page ranges incrementally to avoid loading the entire PDF into memory. Monitor PHP’s `memory_get_usage()` and consider increasing `memory_limit` temporarily for critical operations. Pair with Laravel’s `storage:link` for efficient temp file handling.
- Are there alternatives to this package for more advanced PDF features?
- For production-grade PDF processing, consider **spatie/pdf-temporary-file** (Ghostscript-based) or **barryvdh/laravel-snappy** (PDFtk). These support OCR, encryption, and complex transformations but require additional setup. If you only need merging/splitting, this package is lighter and Laravel-native. Evaluate based on your need for standards like PDF/A or text extraction.
- How do I validate uploaded PDFs before processing to avoid security risks?
- Use Laravel’s `Validator` to check file types (`mime:application/pdf`) and sizes before passing files to `PdfManager`. For deeper validation, integrate a library like `setasign/fpdf` to verify PDF structure. Always store temp files in a secure directory (e.g., `storage/app/temp`) with restrictive permissions (e.g., `chmod 700`). Clean up files post-processing with `Storage::delete()`.
- Does this package work with encrypted or password-protected PDFs?
- No, the package does not support encrypted PDFs out of the box. The underlying FPDF/TCPDF libraries lack built-in decryption. For protected files, pre-process them with a dedicated tool like **Ghostscript** or **PDFtk** before passing to `PdfManager`. Alternatively, prompt users to re-upload unprotected versions in your application flow.
- Can I customize the temp file storage location or cleanup behavior?
- The package defaults to PHP’s `sys_get_temp_dir()`, but you can override this by publishing the config (if available) or extending the `PdfManager` class to inject a custom storage disk. Ensure your solution includes automatic cleanup via Laravel’s `storage:clean` or a scheduled job to prevent temp file accumulation. For production, use `storage:disk('local')` with a dedicated `temp` directory.
- How do I test PDF merging/splitting in a CI/CD pipeline?
- Create test PDFs (e.g., using `FPDF` in a test case) and assert outputs with `Storage::exists()` or file hash comparisons. Mock the `PdfManager` facade in unit tests to isolate logic. For integration tests, use Laravel’s `Artisan::call()` to simulate CLI processing. Test edge cases like malformed PDFs, empty arrays, and large files by injecting known problematic files into your test suite.