Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pdf Manager Bundle Laravel Package

docdigital/pdf-manager-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your Laravel project via Composer:

    composer require docdigital/pdf-manager-bundle
    

    Register the bundle in config/bundles.php (Symfony) or ensure autoloading is configured for Laravel (if used outside Symfony).

  2. First Use Case Inject the PdfManager service into a controller or service:

    use DocDigital\PdfManagerBundle\PdfManager;
    
    public function __construct(private PdfManager $pdfManager) {}
    

    Merge two PDFs:

    $mergedPdf = $this->pdfManager->merge(['file1.pdf', 'file2.pdf']);
    $mergedPdf->saveAs('merged_output.pdf');
    

    Split a PDF into pages:

    $pages = $this->pdfManager->split('input.pdf');
    foreach ($pages as $page) {
        $page->saveAs("page_{$page->getPageNumber()}.pdf");
    }
    
  3. Key Files

    • src/PdfManager.php: Core logic for merging/splitting.
    • tests/: Unit tests for reference (if available).

Implementation Patterns

Workflows

  1. Batch Processing Use loops for large-scale operations (e.g., splitting a 100-page PDF):

    $pages = $this->pdfManager->split('large_file.pdf');
    foreach ($pages as $page) {
        $this->processPage($page); // Custom logic
    }
    
  2. Streaming Large Files Avoid memory issues by streaming PDFs directly to storage:

    $mergedPdf = $this->pdfManager->merge($files);
    $mergedPdf->saveToStream(function ($chunk) {
        // Send chunk to client or write to disk
    });
    
  3. Integration with Storage Combine with Laravel’s Storage facade for cloud storage (S3, etc.):

    use Illuminate\Support\Facades\Storage;
    
    $path = Storage::disk('s3')->path('input.pdf');
    $pages = $pdfManager->split($path);
    

Integration Tips

  • Validation: Validate input files before processing:
    if (!$this->pdfManager->isValidPdf($filePath)) {
        throw new \InvalidArgumentException('Invalid PDF file.');
    }
    
  • Error Handling: Wrap operations in try-catch:
    try {
        $mergedPdf = $pdfManager->merge($files);
    } catch (\Exception $e) {
        Log::error("PDF merge failed: " . $e->getMessage());
    }
    
  • Custom Output: Extend the bundle to add metadata or watermarks post-processing.

Gotchas and Tips

Pitfalls

  1. Memory Limits

    • Splitting/merging large PDFs (>100MB) may hit PHP’s memory_limit. Increase it or stream results:
      memory_limit = 512M
      
    • Use saveToStream() for large files to avoid loading entire PDFs into memory.
  2. File Paths

    • Ensure paths are absolute or correctly resolved. Use Laravel’s storage_path() or public_path() helpers:
      $file = $pdfManager->merge([storage_path('file1.pdf'), storage_path('file2.pdf')]);
      
  3. Dependency Conflicts

    • The bundle relies on setasign/fpdf or similar. Check for version conflicts in composer.json.
  4. Permissions

    • Ensure PHP has write permissions for output directories. Use Laravel’s storage:link if needed.

Debugging

  • Log Outputs: Enable debug mode to log intermediate steps:
    $pdfManager->setDebug(true); // If supported (check bundle docs)
    
  • Test with Small Files: Validate logic with 1–2 page PDFs before scaling.

Extension Points

  1. Custom Formats Override the bundle’s output format (e.g., add encryption):
    $pdfManager->setOutputFormat('encrypted');
    
  2. Event Hooks Extend the bundle by listening to events (if supported) or wrap methods:
    $pdfManager->merge($files)->then(function ($pdf) {
        // Post-merge logic
    });
    
  3. Configuration Adjust settings via config/packages/docdigital_pdf_manager.yaml (if available) or environment variables.

Tips

  • Laravel Artisan Commands: Create a custom command for CLI-based PDF processing:
    php artisan pdf:merge file1.pdf file2.pdf output.pdf
    
  • Queue Jobs: Offload heavy processing to Laravel queues:
    PdfMergeJob::dispatch($files, 'output.pdf')->onQueue('pdf');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views
spatie/ignition-contracts