setasign/fpdf
Classic, dependency-free PDF generator for PHP. Create PDFs on the fly with pages, text, fonts, images, lines, and basic layout control. Widely used for reports, invoices, labels, and simple documents without needing external extensions.
composer require setasign/fpdf. No additional extensions required—pure PHP.require_once 'vendor/autoload.php';
use FPDF\FPDF;
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(0, 10, 'Hello, FPDF!', 0, 1, 'C');
$pdf->Output();
FPDF to add reusable page layout (headers, footers, margins).tutorial/ folder)—work through the first three for layout and text handling.FPDF to define custom Header() and Footer() methods—applies to every page automatically.addInvoiceTable($items) or drawLogo($x, $y) to compose documents modularly.OrderService, CurrencyService) into PDF classes—avoid inline logic. Use DTOs for invoice line items, etc.$pdf->Output('I', 'filename.pdf') → inline browser download$pdf->Output('F', '/path/to/file.pdf') → save to disk (e.g., for attachments)$pdf->Output('S') → capture as string for email attachments or S3 uploadPdfInvoiceGenerator). Use queued jobs for large reports. Store templates in storage/app/templates/—not in resources/.setasign/fpdi + custom font encoding or fallback to setasign/fpdf + setasign/fpdi + SetaPDF for Unicode—but note: fpdf itself doesn’t support UTF-8 natively. For basic accented chars, use utf8_decode() on strings.SetFont() must be called before any text output. Custom fonts require .php metrics files—use ttf2pt1 or makefont tools. Laravel’s storage_path() works well for storing generated font files.SetMargins() and SetAutoPageBreak() are critical—default margins are often too tight for real-world use. Set them in your subclass constructor.'S') and save to a .pdf file manually—open in browser to validate layout before debugging rendering issues.Output() in loops. Generate in chunks, or batch render on workers. Large images? Scale them with Image()’s $w/$h params—don’t rely on FPDF to downsample.PdfStyler, PdfTableBuilder) to avoid monolithic PDF classes. Avoid mutating global state—each PDF instance should be self-contained.How can I help you explore Laravel packages today?