Import pages from existing PDF documents and use them as templates in FPDF

FPDI

Import pages from existing PDF documents and use them as templates in FPDF

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 in FPDF, which was developed by Olivier Plathey. Apart from a copy of FPDF, FPDI does not require any special PHP extensions.

FPDI can also be used with TCPDF (6.x). 

FPDI is published under the MIT license as of version 1.6 (Versions before were released under the Apache 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
<?php
use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfReader;

require_once('fpdf/fpdf.php');
require_once('fpdi2/src/autoload.php');

$pdf = new Fpdi();

$pageCount = $pdf->setSourceFile('Fantastic-Speaker.pdf');
$pageId = $pdf->importPage(1, PdfReader\PageBoundaries::MEDIA_BOX);

$pdf->addPage();
$pdf->useImportedPage($pageId, 10, 10, 90);

$pdf->Output();

About

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

Back then we created a class called FPDF_TPL first, which adds a kind of template feature to FPDF. It was the basis for FPDI. With version 2 we also implemented the functionallity as FpdfTpl in FPDI but internally the main logic of FPDI does not rely on this feature anymore.

Anyhow FpdfTpl is still part of FPDI and still offers many advantages:

  • data of templates are included in a PDF document only once
  • less memory 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.

It's FREE!

The »F« in FPDI stands for »free«: you may use it for any kind of project and adapt it to your needs - the license conditions of the MIT are met nevertheless.

donate via PayPal

Miscellaneous

PDF Documents > 1.4

Do you need support for PDF documents with a version higher than 1.4? Check out the new FPDI PDF-Parser!

Do you like this product?

Then it would be awesome, if you‘d recommend it to your friends!