- How do I install gotenberg/gotenberg-php in a Laravel project?
- Run `composer require gotenberg/gotenberg-php` in your project directory. The package requires PHP 8.1+ and Laravel 8.x or later. No additional Laravel service provider is needed, though you may wrap it in a custom facade for consistency.
- What Laravel versions does this package support?
- The package is compatible with Laravel 8.x, 9.x, and 10.x. It relies on PSR-18 HTTP clients (like Laravel’s built-in `HttpClient` facade), so it integrates natively with modern Laravel versions. Test thoroughly if using Laravel 7.x or earlier.
- Can I use this package to convert Word or Excel files to PDF?
- Yes, the package supports converting Office formats (DOCX, XLSX) to PDF via LibreOffice through the Gotenberg API. Use `Gotenberg::libreoffice()->pdf()->file($filePath)` to process local files or `Gotenberg::libreoffice()->pdf()->url($url)` for remote files.
- How do I handle large file conversions without memory issues?
- Stream responses directly to storage using `$response->getBody()` and avoid loading entire files into memory. For Laravel, use `Storage::disk()->put($filename, $response->getBody())` with chunked writes. Gotenberg also supports streaming for large inputs.
- Is there built-in support for Laravel Queues or background jobs?
- Yes, dispatch conversions as Laravel jobs using `ConvertDocumentJob::dispatch($input, $output)` with `delay()` for async processing. The package integrates with Laravel’s queue system, making it ideal for high-volume or long-running conversions.
- What if the Gotenberg API is down or unresponsive?
- Use Laravel’s retry helper (`retry()`) or implement circuit breakers (e.g., Predis for Redis) to handle API failures gracefully. Log errors with `Log::error()` and consider queue dead-lettering for failed jobs in production.
- How do I authenticate with the Gotenberg API in Laravel?
- Pass authentication tokens via the client: `Gotenberg::chromium($apiUrl)->auth('Bearer', $token)`. For mutual TLS, configure the Laravel `HttpClient` with SSL options before passing it to the client. Store credentials securely using Laravel’s `env()` or `config()`.
- Can I use this package with serverless (e.g., AWS Lambda) or Kubernetes?
- Yes, the package is microservice-friendly. Deploy Gotenberg in containers (Docker/K8s) or serverless (AWS Fargate/Lambda) and configure Laravel to call it via HTTP. Use environment variables for dynamic API URLs and scale Gotenberg independently.
- Are there alternatives to this package for Laravel?
- Alternatives include `thecodingmachine/gotenberg-php-client` (for Gotenberg 6.x) or Symfony’s `GotenbergBundle`. For self-hosted solutions, consider `dompdf/dompdf` (lightweight but limited) or `spipu/html2pdf` (HTML-focused). This package is preferred for modern Laravel apps needing Chromium/LibreOffice.
- How do I test this package in a Laravel application?
- Mock the Gotenberg API using Laravel’s `HttpClient` facade with fake responses in tests. Example: `$client->fake([$apiUrl => Http::response(file_get_contents('test.pdf'), 200)])`. Test edge cases like invalid URLs, timeouts, and large files with `Storage::fake()`.