Skip to content

Commit

Permalink
Initial commit of version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSlabon committed Aug 22, 2017
1 parent a6ad588 commit 9205a48
Show file tree
Hide file tree
Showing 229 changed files with 13,065 additions and 3,215 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
composer.lock
File renamed without changes.
124 changes: 87 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,135 @@ FPDI - Free PDF Document Importer

[![Latest Stable Version](https://poser.pugx.org/setasign/fpdi/v/stable.svg)](https://packagist.org/packages/setasign/fpdi) [![Total Downloads](https://poser.pugx.org/setasign/fpdi/downloads.svg)](https://packagist.org/packages/setasign/fpdi) [![Latest Unstable Version](https://poser.pugx.org/setasign/fpdi/v/unstable.svg)](https://packagist.org/packages/setasign/fpdi) [![License](https://poser.pugx.org/setasign/fpdi/license.svg)](https://packagist.org/packages/setasign/fpdi)

A clone of [FPDI](https://www.setasign.com/fpdi) for GitHub/[Composer](https://packagist.org/packages/setasign/fpdi).
:heavy_exclamation_mark: This document refers to FPDI 2. Version 1 is deprecated and development is discontinued. :heavy_exclamation_mark:

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 is a collection of PHP classes facilitating developers to read pages from existing PDF
documents and use them as templates in [FPDF](http://www.fpdf.org), which was developed by Olivier Plathey. Apart
from a copy of [FPDF](http://www.fpdf.org), FPDI does not require any special PHP extensions.

## Installation with [Composer](https://packagist.org/packages/setasign/fpdi)

FPDI is an add-on for [FPDF](http://fpdf.org/). Additionally FPDI can be used with [TCPDF](http://www.tcpdf.org/).
For completion we added a [FPDF repository](https://github.com/Setasign/FPDF) which simply clones the offical releases.

This package comes without any dependency configuration in the composer.json file. It's up to you to load the desired package as described below.
FPDI can also be used as an extension for [TCPDF](https://github.com/tecnickcom/TCPDF), too.

A basic installation via Composer could be done this way:

```bash
$ composer require setasign/fpdi:1.6.2
```
## Installation with [Composer](https://packagist.org/packages/setasign/fpdi)

or you can include the following in your composer.json file:

```json
{
"require": {
"setasign/fpdi": "1.6.2"
}
}
```
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](https://github.com/Setasign/FPDI-FPDF) and
[TCPDF](https://github.com/Setasign/FPDI-TCPDF).

### Evaluate Dependencies Automatically

To load dependencies automatically we prepared kind of metadata packages. To use FPDI with FPDF use [this](https://github.com/Setasign/FPDI-FPDF) package:

For FPDF add following [package](https://github.com/Setasign/FPDI-FPDF) to your composer.json:
```json
{
"require": {
"setasign/fpdi-fpdf": "1.6.2"
"setasign/fpdi-fpdf": "^2.0"
}
}
```

For TCPDF use [this](https://github.com/Setasign/FPDI-TCPDF):

For TCPDF add following [package](https://github.com/Setasign/FPDI-TCPDF) to your composer.json:
```json
{
"require": {
"setasign/fpdi-tcpdf": "1.6.2"
"setasign/fpdi-tcpdf": "^2.0"
}
}
```

### Manual Dependencies

To support both FPDF and TCPDF its up to you to load the preferred package before the classes of FPDI are loaded. By default FPDI will extend FPDF. If the TCPDF class exists, a new FPDF class will be created which will extend TCPDF while FPDI will extend this.
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:

```json
{
"require": {
"setasign/fpdf": "1.8",
"setasign/fpdi": "1.6.2"
"setasign/fpdf": "^1.8",
"setasign/fpdi": "^2.0"
}
}
```

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

```json
{
"require": {
"tecnickcom/tcpdf": "6.2.13",
"setasign/fpdi": "1.6.2"
"tecnickcom/tcpdf": "^6.2",
"setasign/fpdi": "^2.0"
}
}
```

Additionally you have to trigger composers autoloader for the TCPDF class before you are initiating FPDI:
## Manual Installation

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

```php
require_once('src/autoload.php');
```

If you have a PSR-4 autoloader implemented, just register the src path as follows:
```php
$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
class_exists('TCPDF', true); // trigger Composers autoloader to load the TCPDF class
$pdf = new FPDI();
<?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](https://manuals.setasign.com/fpdi-manual/).
29 changes: 19 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
{
"name": "setasign/fpdi",
"version": "1.6.2",
"homepage": "https://www.setasign.com/fpdi",
"description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.",
"type": "library",
"keywords": ["pdf", "fpdi", "fpdf"],
"license": "MIT",
"autoload": {
"psr-4": {
"setasign\\Fpdi\\": "src/"
}
},
"require": {
"php": "^5.6 || ^7.0",
"ext-zlib": "*"
},
"authors": [
{
"name": "Jan Slabon",
"email": "[email protected]",
"homepage": "https://www.setasign.com"
},
{
"name": "Maximilian Kresse",
"email": "[email protected]",
"homepage": "https://www.setasign.com"
}
],
"autoload": {
"classmap": [
"filters/",
"fpdi.php",
"fpdf_tpl.php",
"fpdi_pdf_parser.php",
"pdf_context.php"
]
},
"suggest": {
"setasign/fpdf": "FPDI will extend this class but as it is also possible to use \"tecnickcom/tcpdf\" as an alternative there's no fixed dependency configured.",
"setasign/fpdi-fpdf": "Use this package to automatically evaluate dependencies to FPDF.",
"setasign/fpdi-tcpdf": "Use this package to automatically evaluate dependencies to TCPDF."
},
"require-dev": {
"phpunit/phpunit": "~5.7",
"setasign/fpdf": "~1.8",
"tecnickcom/tcpdf": "~6.2"
}
}
106 changes: 0 additions & 106 deletions filters/FilterASCII85.php

This file was deleted.

Loading

0 comments on commit 9205a48

Please sign in to comment.