PDF libraries for PHP
Most PHP PDF libraries generate documents; few read them.
- TCPDF creates PDFs from code or simple HTML, with Unicode fonts, barcodes, forms, encryption and signatures. It’s in maintenance mode: version 7 is a compatibility layer over its successor, tc-lib-pdf. LGPL-3.0.
- FPDF and FPDI: FPDF is a small, dependency-free generator; FPDI imports pages from existing PDFs as templates, which is how you merge files or write onto existing documents in PHP. Both MIT.
- Dompdf converts HTML and CSS to PDF. Good for invoices and reports designed as HTML templates. LGPL-2.1.
- mPDF converts HTML to PDF with strong Unicode and right-to-left support, headers, footers, watermarks and page imports (via FPDI). GPL-2.0.
- PdfParser (smalot/pdfparser) reads PDFs in pure PHP: text, text positions and metadata. LGPL-3.0.
Pick Dompdf or mPDF to turn HTML templates into PDFs (mPDF for complex scripts, but note the GPL), TCPDF or FPDF to draw documents from code, FPDI to merge or stamp existing files, and PdfParser to extract text. For heavier tasks, call qpdf, Ghostscript or Poppler tools from PHP.
- Dompdf Dompdf converts HTML and CSS to PDF in PHP. How to install it, render an HTML template to PDF, use Unicode fonts, add page numbers, set metadata.
- FPDF and FPDI FPDF is a small PHP class for generating PDFs; FPDI imports pages from existing PDFs. How to install them, create a PDF, merge and split PDFs.
- mPDF mPDF converts UTF-8 HTML and CSS to PDF in PHP, with strong support for complex scripts. How to install it, create a PDF from HTML, add headers, footers.
- PdfParser smalot/pdfparser is a pure-PHP library to extract text and metadata from PDF files. How to install it, extract text from a PDF or a single page.
- TCPDF TCPDF is a PHP library for generating PDF documents with Unicode text, HTML, barcodes, forms and encryption. How to install it (including fonts in version 7).