• Stars
    star
    1,047
  • Rank 43,853 (Top 0.9 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 9 years ago
  • Updated 20 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF.

FPDI - Free PDF Document Importer

Latest Stable Version Total Downloads Latest Unstable Version License

❗ This document refers to FPDI 2. Version 1 is deprecated and development is discontinued. ❗

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 as an extension for TCPDF or tFPDF, too.

Installation with Composer

Because FPDI can be used with FPDF, TCPDF or tFPDF we haven't added a fixed dependency in the main composer.json file. You need to add the dependency to the PDF generation library of your choice yourself.

To use FPDI with FPDF include following in your composer.json file:

{
    "require": {
        "setasign/fpdf": "1.8.*",
        "setasign/fpdi": "^2.0"
    }
}

If you want to use TCPDF, you have to update your composer.json to:

{
    "require": {
        "tecnickcom/tcpdf": "6.3.*",
        "setasign/fpdi": "^2.0"
    }
}

If you want to use tFPDF, you have to update your composer.json to:

{
    "require": {
        "setasign/tfpdf": "1.31.*",
        "setasign/fpdi": "^2.3"
    }
}

Manual Installation

If you do not use composer, just require the autoload.php in the /src folder:

require_once('src/autoload.php');

If you have a PSR-4 autoloader implemented, just register the src path as follows:

$loader = new \Example\Psr4AutoloaderClass;
$loader->register();
$loader->addNamespace('setasign\Fpdi', 'path/to/src/');

Changes to Version 1

Version 2 is a complete rewrite from scratch of FPDI which comes with:

  • Namespaced code
  • Clean and up-to-date code base and style
  • PSR-4 compatible autoloading
  • Performance improvements by up to 100%
  • Less memory consumption
  • Native support for reading PDFs from strings or stream-resources
  • Support for documents with "invalid" data before their file-header
  • Optimized page tree resolving
  • Usage of individual exceptions
  • Several test types (unit, functional and visual tests)

We tried to keep the main methods and logical workflow the same as in version 1 but please notice that there were incompatible changes which you should consider when updating to version 2:

  • You need to load the code using the src/autoload.php file instead of classes/FPDI.php.
  • The classes and traits are namespaced now: setasign\Fpdi
  • Page boundaries beginning with a slash, such as /MediaBox, are not supported anymore. Remove the slash or use a constant of PdfReader\PageBoundaries.
  • The parameters $x, $y, $width and $height of the useTemplate() or getTemplateSize() method have more logical correct default values now. Passing 0 as width or height will result in an InvalidArgumentException now.
  • The return value of getTemplateSize() had changed to an array with more speaking keys and reusability: Use width instead of w and height instead of h.
  • If you want to use FPDI with TCPDF you need to refactor your code to use the class Tcpdf\Fpdi (since 2.1; before it was TcpdfFpdi) instead of FPDI.

Example and Documentation

A simple example, that imports a single page and places this onto a new created page:

<?php
use setasign\Fpdi\Fpdi;
// or for usage with TCPDF:
// use setasign\Fpdi\Tcpdf\Fpdi;

// or for usage with tFPDF:
// use setasign\Fpdi\Tfpdf\Fpdi;

// setup the autoload function
require_once('vendor/autoload.php');

// initiate FPDI
$pdf = new Fpdi();
// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile("Fantastic-Speaker.pdf");
// import page 1
$tplId = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
$pdf->useTemplate($tplId, 10, 10, 100);

$pdf->Output();            

A full end-user documentation and API reference is available here.

More Repositories

1

FPDF

FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
PHP
704
star
2

FPDI-FPDF

ABANDONED! A kind of metadata package for Composer with fixed dependencies for the latest versions of FPDI and FPDF.
96
star
3

FPDI-TCPDF

ABANDONED! A kind of metadata package for Composer with fixed dependencies for the latest versions of FPDI and TCPDF.
62
star
4

tFPDF

This class is a modified version of FPDF that adds UTF-8 support.
PHP
34
star
5

fpdi-protection

A FPDI compatible and enhanced version of the FPDF_Protection script.
PHP
31
star
6

php-stub-generator

A tool to generate stub-files for your php classes.
PHP
28
star
7

SetaFPDF

A clone of FPDF with an almost compatible interface while using SetaPDF-Core internally for the PDF generation.
PHP
18
star
8

Cloud-KMS-CSR

Certificate signing request and self-signed certificate generator/updater for cloud Key Management Systems
PHP
7
star
9

SetaPDF-Demos

PHP
6
star
10

ComposerIoncubeLicenseInstaller

Composer installer plugin for ioncube licenses
PHP
6
star
11

SetaPDF-Signer-Addon-GlobalSign-DSS

A SetaPDF-Signer component signature module for the GlobalSign Digital Signing Service.
PHP
6
star
12

FPDI-tFPDF

ABANDONED! A kind of metadata package for Composer with fixed dependencies for the latest versions of FPDI and tFPDF
4
star
13

SetaPDF-Signer-Addon-Google-Cloud-KMS

A SetaPDF-Signer component signature module for the Google Cloud Key Management Service.
PHP
3
star
14

SetaPDF-Signer-Addon-AWS-KMS

A SetaPDF-Signer component signature module for the AWS Key Management Service.
PHP
3
star
15

phpcs-teamcity-report

A phpcs reporter for teamcity using the Inspection service messages
PHP
2
star
16

SetaPDF-Signer-Addon-Globaltrust-Trust2Go

A signature add-on for the SetaPDF-Signer component for TRUST2GO by GLOBALTRUST
PHP
2
star
17

SetaPDF-Signer-Addon-Azure-KeyVault

A SetaPDF-Signer component signature module for the Azure KeyVault.
PHP
2
star
18

SetaPDF-Signer-Addon-SwisscomAIS

A SetaPDF-Signer component signature module and batch processor for the Swisscom Signing Service.
PHP
1
star
19

SetaPDF-Signer-Addon-eID-Easy

PHP
1
star
20

SetaPDF-Signer-Addon-QuoVadis

A SetaPDF-Signer component signature module for the QuoVadis Signing and Validation Service.
PHP
1
star
21

SetaPDF-Signer-Addon-PKCS11

Signature module for the SetaPDF-Signer component to access keys on PKCS11 devices.
PHP
1
star