Print PDF invoices from Laravel
Render a Laravel invoice PDF with Dompdf or Snappy, then POST the bytes. The office printer is selected by printer_code.
For Laravel billing code that should also print
Overview
You already render invoice PDFs for email. The print path takes those same bytes. Dompdf's output(), a Snappy temporary file, or a stored invoice on disk all end as base64 content with content_type pdf.
Send the office printer's code, which may differ from a warehouse label printer. options can include duplex. The driver may ignore it; check one page.
Email and print are two side effects. A failed print should not roll back a sent email unless your business rule says so. Store the job id on the invoice either way.
Integration steps
- 01
Create an API key on the server
Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.
- 02
Install the agent beside the printer
Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.
- 03
POST /v1/print-jobs
content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.
- 04
Reuse the idempotency key on retry
A new key means a second physical print. HTTP 409 means the same key was reused with a different body.
- 05
Read the job before you tell the user
GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.
PHP
<?php
// Laravel invoice PDF
$payload = [
'printer_code' => (int) getenv('PRINTER_CODE'),
'content_type' => 'pdf',
'content' => base64_encode($pdf),,
'copies' => 1,
];
$ch = curl_init('https://api.printbase.cloud/v1/print-jobs');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('PRINTBASE_API_KEY'),
'Content-Type: application/json',
'Idempotency-Key: ' . 'inv-'.$invoice->id,
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$body = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 300) {
throw new RuntimeException($body);
}
$job = json_decode($body, true); // id, status=queued
Details for this setup
Render first
If the PDF is blank, fix the view. The API will faithfully print a blank page. The agent prints only what you send; it does not fetch the document from the platform for you.
Do not pass a signed route as content_url unless the agent can fetch it
Laravel signed URLs that require cookies will fail in the agent with DOWNLOAD_FAILED. Prefer base64 for private invoices.
Questions
Which PDF library?
Any that gives bytes. The print API does not integrate a specific one.
Queue the print?
Yes. Implement ShouldQueue and keep the idempotency key as the invoice number.
Multi-tenant printer?
Look up printer_code on the team model. Do not share one code across tenants that have their own offices.
Duplex? in this setup
Pass options.duplex. Confirm on the device. It is not enforced by the API.
Free plan: 100 jobs a month on one computer, no card.