header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="invoice.pdf"'); echo $pdf->render(); Laminas PDF can read, modify, and save existing documents.

function generateInvoice($invoiceNumber, $date, $customer, $items, $total) { $pdf = new PdfDocument(); $page = $pdf->newPage(Page::SIZE_A4); $pdf->pages[] = $page;

// Load an existing PDF $pdf = PdfDocument::load('/path/to/document.pdf'); // Add a watermark to every page foreach ($pdf->pages as $page) { $page->setFont(Font::fontWithName(Font::FONT_HELVETICA), 60); $page->setFillColor(new Rgb(0.8, 0.8, 0.8)); $page->rotate(250, 400, deg2rad(45)); $page->drawText('CONFIDENTIAL', 200, 400); $page->rotate(250, 400, deg2rad(-45)); // rotate back }