Giter VIP home page Giter VIP logo

fpdi's Introduction

FPDI - Free PDF Document Importer

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

โ— 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, too.

Installation with Composer

Because FPDI can be used with FPDF or TCPDF we didn't added a fixed dependency in the main composer.json file but we added metadata packages for both FPDF and TCPDF.

Evaluate Dependencies Automatically

For FPDF add following package to your composer.json:

{
    "require": {
        "setasign/fpdi-fpdf": "^2.0"
    }
}

For TCPDF add following package to your composer.json:

{
    "require": {
        "setasign/fpdi-tcpdf": "^2.0"
    }
}

Manual Dependencies

If you don't want to use the metadata packages, it is up to you to add the dependencies to your composer.json file.

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, your have to update your composer.json respectively to:

{
    "require": {
        "tecnickcom/tcpdf": "^6.2",
        "setasign/fpdi": "^2.0"
    }
}

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 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;

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

// initiate FPDI
$pdf = new Fpdi\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.

fpdi's People

Contributors

janslabon avatar maximiliankresse avatar vincent-- avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.