Weave 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

Pdfcrowd Php Laravel Package

pdfcrowd/pdfcrowd-php

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require pdfcrowd/pdfcrowd-php
    

    Add your API username and password to .env:

    PDFCROWD_USERNAME=your_username
    PDFCROWD_PASSWORD=your_password
    
  2. First Use Case: Generate a PDF from HTML

    use Pdfcrowd\Pdfcrowd;
    
    $client = new Pdfcrowd(getenv('PDFCROWD_USERNAME'), getenv('PDFCROWD_PASSWORD'));
    $pdf = $client->convertHtml('<h1>Hello, PDF!</h1>');
    $pdf->saveAs('output.pdf');
    
  3. Key Files to Review

    • vendor/pdfcrowd/pdfcrowd-php/src/Pdfcrowd.php (core class)
    • vendor/pdfcrowd/pdfcrowd-php/README.md (API docs, examples)

Implementation Patterns

Common Workflows

  1. Dynamic PDF Generation

    // Generate PDFs from Blade templates
    $html = view('invoices.pdf', ['invoice' => $invoice])->render();
    $pdf = $client->convertHtml($html);
    
  2. Batch Processing

    foreach ($users as $user) {
        $pdf = $client->convertHtml($user->generateHtml());
        $pdf->saveAs("storage/app/user_{$user->id}.pdf");
    }
    
  3. Integration with Laravel Queues

    // Job class
    public function handle() {
        $pdf = $client->convertHtml($this->html);
        Storage::put("pdfs/{$this->filename}.pdf", $pdf->getBytes());
    }
    
  4. Custom Headers & Options

    $pdf = $client->convertHtml($html, [
        'page_size' => 'A4',
        'margin_top' => '1cm',
        'margin_bottom' => '1cm',
    ]);
    

Best Practices

  • Cache API Responses: Store generated PDFs in storage/app/pdf to avoid redundant API calls.
  • Error Handling: Wrap API calls in try-catch blocks for PdfcrowdException.
  • Environment-Specific Config: Use config('pdfcrowd') for credentials in production.

Gotchas and Tips

Pitfalls

  1. API Rate Limits

    • Pdfcrowd enforces usage limits. Monitor API calls in config/pdfcrowd.php:
      'usage_limit' => env('PDFCROWD_USAGE_LIMIT', 1000), // Default: 1000 pages/month
      
    • Fix: Implement a queue system for high-volume generation.
  2. HTML/CSS Quirks

  3. Memory Limits

    • Large HTML payloads may hit PHP’s memory_limit.
    • Fix: Stream responses or increase memory_limit in php.ini.
  4. Authentication Caching

    • The client caches credentials. Clear cache if switching environments:
      $client->clearCache();
      

Debugging Tips

  • Enable Verbose Logging
    $client = new Pdfcrowd($username, $password, [
        'verbose' => true,
        'log_file' => storage_path('logs/pdfcrowd.log'),
    ]);
    
  • Check HTTP Status Codes Inspect $pdf->getHttpStatus() for errors (e.g., 403 = invalid credentials).

Extension Points

  1. Custom Headers
    $client->setCustomHeader('X-Custom-Header', 'value');
    
  2. Proxy Support
    $client = new Pdfcrowd($username, $password, [
        'proxy' => 'http://proxy.example.com:8080',
    ]);
    
  3. Event Listeners Extend Pdfcrowd to log conversions:
    $client->addListener(function ($event) {
        Log::info("PDF Event: {$event->getType()}", $event->getData());
    });
    
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator