FPDI
Import pages from existing PDFs as templates in FPDF, TCPDF, and tFPDF
Repository Health
Technical Analysis
FPDI (Free PDF Document Importer) is a collection of PHP classes that let developers read pages from existing PDF documents and reuse them as templates in FPDF. Apart from a PDF generation library to extend, FPDI does not require any special PHP extensions, making it easy to drop into an existing stack.
Because it can extend FPDF, TCPDF, or tFPDF, FPDI does not declare a fixed dependency on any one of them; you pick your PDF engine and FPDI plugs in on top. This makes it the standard tool for stamping, watermarking, filling, and assembling documents from pre-made PDF templates in PHP.
What You Get
- A PDF parser that reads pages, cross-reference tables, and object streams from existing files
- importPage() and useTemplate() APIs to reuse source pages as templates
- Traits that extend FPDF, TCPDF, or tFPDF without a fixed dependency on any one
- Support for placing imported pages at any position, scale, and rotation
Common Use Cases
- Filling pre-designed PDF forms and templates with dynamic data
- Stamping watermarks, signatures, or headers onto existing documents
- Merging, splitting, and reordering pages from multiple source PDFs
Under The Hood
Architecture - FPDI splits cleanly into a PDF-reading layer and an integration layer. The PdfParser subtree (PdfParser.php, Tokenizer, StreamReader, CrossReference, Filter, Type) parses source documents, resolving cross-reference tables and object streams and decoding standard filters. FpdiTrait plus engine-specific traits (FpdfTrait for FPDF, and TCPDF/tFPDF variants) inject the importPage/useTemplate behavior into whichever generator you extend, while FpdfTpl and GraphicsState manage template objects and graphics-state so imported pages render correctly.
Tech Stack - Pure PHP supporting 7.2 through 8.5 with only the zlib extension required; the PDF generator (setasign/fpdf, tecnickcom/tcpdf, or setasign/tfpdf) is a suggested rather than fixed dependency. Distributed via Composer with PSR-4 autoloading under setasign\Fpdi.
Code Quality - Actively maintained with frequent releases and a substantial test suite (roughly 78 test files under PHPUnit) plus PHP_CodeSniffer for style. The parser is factored into small, typed classes per PDF object type, reflecting a mature, well-organized codebase.
API Design - The public API is compact and task-focused: setSourceFile(), importPage(), getTemplateSize(), and useTemplate() cover the common workflow, and the trait-based design means the same methods work regardless of the underlying PDF engine. Clear documentation and manuals on setasign.com support onboarding, with the main nuance being awareness of which PDF features the free parser supports.
Used by 2 apps in this directory
Invoice Ninja
Invoicing Finance · Project Management
Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.
OpnForm
Forms Surveys · Marketing
Build unlimited, embeddable forms with no code — powered by AI, logic rules, and real-time analytics