bytes/docraptor
Lightweight PHP 5 DocRaptor API client to convert HTML into PDF or Excel. Create a document, set HTML content, and send it via cURL with your DocRaptor API key. Supports test mode and exception handling.
Client class can be easily instantiated and injected into Laravel services (e.g., via bind() in AppServiceProvider).PdfDocument), HTTP communication (HttpClient), and API logic (Client), which maps neatly to Laravel’s service-layer architecture.docraptor.conversion.completed) for post-processing (e.g., storage, notifications).Http client (v9+) can replace Bytes\Docraptor\Http\Client for consistency, reducing external dependencies..env (e.g., DOCRAPTOR_API_KEY, DOCRAPTOR_TEST_MODE).DocRaptorJob extending ShouldQueue) for scalability.Response class.DocRaptorException could extend RuntimeException). Custom exceptions should be defined for better integration with Laravel’s error handling.Http facade.spatie/pdf-to-html) that offer similar functionality with lower risk?Client as a singleton/bound interface in AppServiceProvider:
$this->app->singleton(DocRaptorClient::class, function ($app) {
return new Client(
new HttpClient(), // or Laravel's Http client
config('docraptor.api_key'),
config('docraptor.test_mode')
);
});
config/docraptor.php) for API key, timeouts, and async settings.Bytes\DocRaptor\Http\Client with Laravel’s Http client for consistency:
use Illuminate\Support\Facades\Http;
$client = new Client(Http::macroable(), config('docraptor.api_key'));
Storage facade to save outputs:
Storage::put('pdfs/report.pdf', $pdf->getContent());
HttpClient with Laravel’s Http client.Client to the service container.DocRaptor) for convenience:
facade(DocRaptor::class, DocRaptorClient::class);
DocRaptorJob for async conversions:
class DocRaptorJob implements ShouldQueue {
public function handle(DocRaptorClient $client) {
$client->convert($this->document)->then(...);
}
}
logs table or a third-party service (e.g., Sentry).curl. No conflicts with Laravel’s core dependencies..env and config files.DocRaptor::pdf($html)->saveAs('file.pdf')).Http client).curl), but ensure PHP version compatibility.spatie/laravel-queue-retries).Illuminate\Support\Facades\Cache).redis with afterCommit).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| DocRaptor API downtime | PDF/Excel generation fails | Fallback to a local renderer (e.g., Dompdf) |
| API key revoked | All conversions fail | Rotate keys via .env and implement validation |
| Large HTML payloads | Timeouts or memory issues | Stream HTML in chunks; use async processing |
| Rate limiting | Queue backlog | Implement exponential backoff and caching |
| Package deprecation | Broken functionality | Fork and maintain or switch to an alternative |
docs/integration.md).php artisan docraptor:test to validate API connectivity).How can I help you explore Laravel packages today?