PDF Generation Implementation
PDF generation from HTML: invoices, receipts, reports, certificates. Options: server-side (mPDF, TCPDF, Puppeteer) or browser (client library). Server-side allows batch processing, emailing, storage.
PHP: mPDF or TCPDF
class InvoiceController
{
public function download(Invoice $invoice)
{
$html = view('invoices.template', ['invoice' => $invoice])->render();
$pdf = new \Mpdf\Mpdf();
$pdf->WriteHTML($html);
return response($pdf->Output('invoice.pdf', 'S'))
->header('Content-Type', 'application/pdf')
->header('Content-Disposition', 'attachment; filename="invoice.pdf"');
}
}
Node.js: Puppeteer
import puppeteer from 'puppeteer';
async function generatePDF(htmlContent: string): Promise<Buffer> {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(htmlContent);
const pdf = await page.pdf({ format: 'A4' });
await browser.close();
return pdf;
}
Async generation with queue
For large volumes: generate in background, store in S3, send download link via email.
Implementation timeline
Basic PDF generation: 1–2 days. With queue, templates, and email: 2–3 days.







