Php - Web Development With Laminas Pdf
// 3. Set up font (built-in Helvetica) $font = Font::fontWithName(Font::FONT_HELVETICA); $page->setFont($font, 36);
// Table headers $page->setFillColor(new Rgb(0.9, 0.9, 0.9)); $page->drawRectangle(50, $y - 20, 550, $y, Page::SHAPE_DRAW_FILLED); $page->setFillColor(new Rgb(0, 0, 0)); $page->setFont($fontBold, 10); $page->drawText('Description', 60, $y - 10); $page->drawText('Qty', 350, $y - 10); $page->drawText('Unit Price', 420, $y - 10); $page->drawText('Total', 500, $y - 10); $y -= 40; php web development with laminas pdf
// Total line $y -= 20; $page->drawLine(350, $y, 550, $y); $page->setFont($fontBold, 12); $page->drawText('TOTAL: $' . number_format($total, 2), 450, $y - 20); // Step 3: Draw Unicode text (e
header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="invoice.pdf"'); echo $pdf->render(); Laminas PDF can read, modify, and save existing documents. pages as $page) { $page->
// Step 3: Draw Unicode text (e.g., Arabic, Chinese, Emojis) $page->drawText('こんにちは世界', 100, 500, 'UTF-8'); : Embedded fonts increase file size. Use core fonts when possible. Adding Images Laminas PDF supports JPEG and PNG images.
// 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 }
Run via built-in PHP server: