gotenberg/gotenberg-php
PHP client for the Gotenberg API to convert documents to PDF using Chromium/LibreOffice. Build requests for URL, HTML, Markdown, and Office files, then stream or save outputs. Compatible with Gotenberg 8.x via client v2.x.
Gotenberg::chromium()->pdf()->url()), which is clean, composable, and testable, fitting Laravel’s dependency injection and service container.HttpClient, Guzzle).HttpClient facade (PSR-18 compliant).Gotenberg::dispatch()).Storage::disk()->put()) for saving converted files.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| API Dependency | Tight coupling to Gotenberg API (versioning, uptime, latency). | Use retries (Laravel’s retry helper) and circuit breakers (e.g., Predis). |
| Resource Intensity | Chromium/LibreOffice conversions are CPU/memory-heavy; may require dedicated infrastructure. | Deploy Gotenberg in scaled containers (K8s, ECS) or use serverless (e.g., AWS Fargate). |
| Error Handling | Custom exceptions (GotenbergApiErrored) need integration with Laravel’s error handling. |
Wrap API calls in try-catch blocks and log errors via Laravel’s Log facade. |
| File Handling | Large files (e.g., multi-page PDFs) may exhaust memory or fail uploads. | Stream responses ($response->getBody()) and use chunked storage (e.g., fopen). |
| Version Skew | Laravel app and Gotenberg client must align with API versions (e.g., v2.x for 8.x). |
Pin versions in composer.json and test against staging Gotenberg instances. |
| Laravel Component | Integration Strategy | Example Implementation |
|---|---|---|
| HTTP Client | Use Laravel’s HttpClient facade or Guzzle adapter. |
$client = HttpClient::withOptions(['timeout' => 30]); |
| Queues | Dispatch conversions as delayed jobs (e.g., ConvertDocumentJob). |
ConvertDocumentJob::dispatch($url, $outputPath)->delay(now()->addMinutes(5)); |
| Storage | Save outputs to Laravel Filesystem (S3, local, etc.). | Storage::disk('public')->put($filename, $response->getBody()); |
| Validation | Validate inputs (e.g., file types, URLs) using Laravel’s Form Requests. | `public function rules(): array { return ['url' => 'required |
| Events | Emit events (e.g., DocumentConverted) for post-processing (e.g., notifications). |
event(new DocumentConverted($filename)); |
| Service Container | Register a Gotenberg service for dependency injection. | app()->bind(GotenbergClient::class, fn() => new GotenbergClient($apiUrl)); |
/convert).app/Services/GotenbergService.php).v2.x requires Gotenberg 8.x. Downgrade if needed (e.g., v1.x for 7.x).HttpClient.Gotenberg::chromium()->pdf()).| Task | Effort | Notes |
|---|---|---|
| Dependency Updates | Medium | Monitor Gotenberg client and PHP versions for compatibility. |
| Gotenberg Patches | High | Requires Docker rebuilds or K8s rolling updates for API fixes. |
| Client Logging | Low | Extend GotenbergApiErrored to log correlation IDs and input/output metadata. |
| Deprecation Handling | Medium | Update code when Gotenberg deprecates methods ( |
How can I help you explore Laravel packages today?