Skip to content

phpdftk

Every PDF spec object is a PHP class. Zero dependencies. Spec-compliant output.

Three API levels

Pick the abstraction that fits. Level 2 auto-wraps text and paginates. Level 1 gives spatial drawing with explicit coordinates. Level 0 is the raw PDF object model. Drop down a level any time via escape hatches.

Read + Write

Full reader and writer in one library. Parse existing PDFs into typed objects, extract text, search content, inspect structure — then generate new PDFs with the same object model.

Toolkit

High-level pipelines for common tasks: text extraction with search, page selection, metadata editing, form filling, page merging, stamping, and more.

Standards Compliance

Validate against 8 ISO standards and 31 conformance levels: PDF/A, PDF/UA, PDF/X, PDF/VT, PDF/E, PDF/R, ZUGFeRD/Factur-X, and PDF/mail. Constraints enforced at generation time.

Fast

3-30x faster than TCPDF, mPDF, and Dompdf. Competitive with FPDF while offering vastly more features. 83% code coverage, 275 external validation tests passing.

// Level 2 — no PDF knowledge required
$pdf = new Pdf();
$pdf->addHeading('Quarterly Report', 1);
$pdf->addText('Revenue increased 23% year-over-year...');
$pdf->save('report.pdf');
// Level 1 — spatial drawing, explicit coordinates
$writer = new PdfWriter();
$page = $writer->addPage(612, 792);
$page->drawText('Hello', 72, 720, $font, 24);
$page->drawRectangle(72, 600, 200, 100, fill: $blue);
$writer->save('drawing.pdf');
// Level 0 — raw PDF objects
$fw = new PdfFileWriter();
$catalog = new Catalog();
$fw->setCatalog($catalog);
// ... full object-model control

Every object in ISO 32000-2:2020 (PDF 2.0) maps 1:1 to a PHP class. Every /Field from the spec maps to a camelCase property. The object model covers:

  • 28 Catalog fields, 32 Page fields, 26 annotation subtypes
  • All 69 content stream operators
  • 7 font types with TrueType/OpenType embedding and subsetting
  • AES-128/256 and RC4 encryption with PKCS#7 digital signatures
  • Tagged PDF, optional content groups, 3D annotations, multimedia

275 external validation tests passing across QPDF, veraPDF, Arlington PDF Model, Matterhorn (PDF/UA), and JHOVE. 15 focused packages, 8 ISO conformance standards with 31 levels.