Skip to content

Commit

Permalink
Update to FPDI 1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSlabon committed May 11, 2017
1 parent 5b899b2 commit a6ad588
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 39 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Setasign - Jan Slabon, https://www.setasign.com
Copyright (c) 2017 Setasign - Jan Slabon, https://www.setasign.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ This package comes without any dependency configuration in the composer.json fil
A basic installation via Composer could be done this way:

```bash
$ composer require setasign/fpdi:1.6.1
$ composer require setasign/fpdi:1.6.2
```

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

```json
{
"require": {
"setasign/fpdi": "1.6.1"
"setasign/fpdi": "1.6.2"
}
}
```
Expand All @@ -37,7 +37,7 @@ To load dependencies automatically we prepared kind of metadata packages. To use
```json
{
"require": {
"setasign/fpdi-fpdf": "1.6.1"
"setasign/fpdi-fpdf": "1.6.2"
}
}
```
Expand All @@ -47,7 +47,7 @@ For TCPDF use [this](https://github.com/Setasign/FPDI-TCPDF):
```json
{
"require": {
"setasign/fpdi-tcpdf": "1.6.1"
"setasign/fpdi-tcpdf": "1.6.2"
}
}
```
Expand All @@ -62,7 +62,7 @@ To use FPDI with FPDF include following in your composer.json file:
{
"require": {
"setasign/fpdf": "1.8",
"setasign/fpdi": "1.6.1"
"setasign/fpdi": "1.6.2"
}
}
```
Expand All @@ -72,8 +72,8 @@ If you are using TCPDF, your have to update your composer.json respectively to:
```json
{
"require": {
"tecnickcom/tcpdf": "6.2.12",
"setasign/fpdi": "1.6.1"
"tecnickcom/tcpdf": "6.2.13",
"setasign/fpdi": "1.6.2"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setasign/fpdi",
"version": "1.6.1",
"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",
Expand Down
4 changes: 2 additions & 2 deletions filters/FilterASCII85.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions filters/FilterASCIIHexDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions filters/FilterLZW.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions fpdf_tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

if (!class_exists('fpdi_bridge')) {
Expand Down
36 changes: 24 additions & 12 deletions fpdi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

if (!class_exists('FPDF_TPL')) {
Expand All @@ -22,7 +22,7 @@ class FPDI extends FPDF_TPL
*
* @string
*/
const VERSION = '1.6.1';
const VERSION = '1.6.2';

/**
* Actual filename
Expand Down Expand Up @@ -88,23 +88,35 @@ class FPDI extends FPDF_TPL
*
* @param string $filename A valid path to the PDF document from which pages should be imported from
* @return int The number of pages in the document
* @throws Exception
*/
public function setSourceFile($filename)
{
$_filename = realpath($filename);
if (false !== $_filename)
$filename = $_filename;

$this->currentFilename = $filename;

if (!isset($this->parsers[$filename])) {
$this->parsers[$filename] = $this->_getPdfParser($filename);
$this->setPdfVersion(
max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion())
);
}
$currentFilename = $this->currentFilename;
$currentParser = $this->currentParser;

$this->currentParser = $this->parsers[$filename];
try {
$this->currentFilename = $filename;

if (!isset($this->parsers[$filename])) {
$this->parsers[$filename] = $this->_getPdfParser($filename);
$this->setPdfVersion(
max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion())
);
}

$this->currentParser = $this->parsers[$filename];

} catch (Exception $e) {
unset($this->parsers[$filename]);
$this->currentFilename = $currentFilename;
$this->currentParser = $currentParser;
throw $e;
}

return $this->parsers[$filename]->getPageCount();
}
Expand Down
4 changes: 2 additions & 2 deletions fpdi_bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

/**
Expand Down
12 changes: 10 additions & 2 deletions fpdi_pdf_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (http://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

if (!class_exists('pdf_parser')) {
Expand Down Expand Up @@ -155,6 +155,10 @@ public function getContent()
if (isset($this->_pages[$this->pageNo][1][1]['/Contents'])) {
$contents = $this->_getPageContent($this->_pages[$this->pageNo][1][1]['/Contents']);
foreach ($contents AS $tmpContent) {
if ($tmpContent[0] !== pdf_parser::TYPE_STREAM) {
continue;
}

$buffer .= $this->_unFilterStream($tmpContent) . ' ';
}
}
Expand Down Expand Up @@ -335,6 +339,10 @@ protected function _readPages(&$pages, &$result)

foreach ($kids as $v) {
$pg = $this->resolveObject($v);
if ($pg[0] !== pdf_parser::TYPE_OBJECT) {
throw new Exception('Invalid data type in page tree.');
}

if ($pg[1][1]['/Type'][1] === '/Pages') {
// If one of the kids is an embedded
// /Pages array, resolve it as well.
Expand Down
15 changes: 11 additions & 4 deletions pdf_context.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

/**
Expand Down Expand Up @@ -67,7 +67,14 @@ public function __construct(&$f)
public function getPos()
{
if ($this->_mode == 0) {
return ftell($this->file);
if (feof($this->file)) {
$stat = fstat($this->file);
fseek($this->file, $stat['size']);
}

$pos = ftell($this->file);

return $pos;
} else {
return 0;
}
Expand All @@ -85,7 +92,7 @@ public function reset($pos = null, $l = 100)
{
if ($this->_mode == 0) {
if (!is_null($pos)) {
fseek ($this->file, $pos);
fseek($this->file, $pos);
}

$this->buffer = $l > 0 ? fread($this->file, $l) : '';
Expand Down
4 changes: 2 additions & 2 deletions pdf_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* This file is part of FPDI
*
* @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1
* @version 1.6.2
*/

/**
Expand Down

0 comments on commit a6ad588

Please sign in to comment.