Article : Free PDF Document Importer

Free PDF Document Importer

FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates inFPDF, which was developed by Olivier Plathey. Apart from a copy ofFPDF, FPDI does not require any special PHP extensions.

As of version 1.2.1 FPDI can also be used withTCPDF.

FPDI is published under theApache Software License, Version 2.0.

The usage is very easy: open the document, put a page into a template, and use it like an image!

<?php
require_once('fpdf.php');
require_once('fpdi.php');

$pdf = new FPDI();

$pageCount = $pdf->setSourceFile("Fantastic-Speaker.pdf");
$tplIdx = $pdf->importPage(1, '/MediaBox');

$pdf->addPage();
$pdf->useTemplate($tplIdx, 10, 10, 90);

$pdf->Output();

About

FPDI is the first PHP/PDF script by Setasign. Inspired by an article of Marco Tabini in thephp[architect]magazine, Setasign wrote the first version of FPDI in 2004.

It is based on another extension for FPDF that adds a kind of template feature to FPDF: FPDF_TPL. This class is a requirement for FPDI and can be downloaded in thedownloads area as well.

FPDF_TPL does not only prepare FPDF for FPDI, but offers many other advantages:

  • data of templates are included in a PDF documentonly once
  • lessmemory usage
  • less generation time
  • smaller PDF files
  • recursive template support (use of templates in templates)

Examples of use:

  • Header generation
  • Grids for large tables over several pages
  • Table headers
  • write behind or in front of a template
  • resize a template after creation
  • etc.