Upgrade FPDI libraries

This commit is contained in:
Laurent Destailleur 2010-09-16 17:54:00 +00:00
parent 5929f14ea2
commit 30ed46efd0
13 changed files with 1396 additions and 1430 deletions

View File

@ -14,8 +14,8 @@ ArtiChow 1.07 Public Domain Yes Graphics
EFC/XFSS 1.0.1 LGPL 3.0 Yes Enhanced File Crypt/Extended File Stealth System EFC/XFSS 1.0.1 LGPL 3.0 Yes Enhanced File Crypt/Extended File Stealth System
FCKEditor 2.6.4 LGPL 2.1 or Mozilla PL 1.0 Yes Editor WYSIWYG FCKEditor 2.6.4 LGPL 2.1 or Mozilla PL 1.0 Yes Editor WYSIWYG
FPDF 1.6 Public domain Yes PDF generation (original code is modified) FPDF 1.6 Public domain Yes PDF generation (original code is modified)
FPDF_TPL 1.1.4 Apache Software License 2.0 No GPL3 only PDF templates management FPDF_TPL 1.1.5 Apache Software License 2.0 No GPL3 only PDF templates management
FPDI 1.3.2 Apache Software License 2.0 No GPL3 only PDF templates management FPDI 1.3.4 Apache Software License 2.0 No GPL3 only PDF templates management
FPDI_Protection 1.0.3 Apache Software License 2.0 No GPL3 only PDF encryption (8 files) FPDI_Protection 1.0.3 Apache Software License 2.0 No GPL3 only PDF encryption (8 files)
GeoIP x.x Yes GeoIP Maxmind conversion GeoIP x.x Yes GeoIP Maxmind conversion
iWebkit 5.0.4 LGPL 3.0 Yes Iphone templates framework iWebkit 5.0.4 LGPL 3.0 Yes Iphone templates framework

View File

@ -1,6 +1,6 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //

View File

@ -1,33 +1,33 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
require_once('FilterASCII85.php'); require_once('FilterASCII85.php');
class FilterASCII85_FPDI extends FilterASCII85 { class FilterASCII85_FPDI extends FilterASCII85 {
var $fpdi; var $fpdi;
function FPDI_FilterASCII85(&$fpdi) { function FilterASCII85_FPDI(&$fpdi) {
$this->fpdi =& $fpdi; $this->fpdi =& $fpdi;
} }
function error($msg) { function error($msg) {
$this->fpdi->error($msg); $this->fpdi->error($msg);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //

View File

@ -1,33 +1,33 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
require_once('FilterLZW.php'); require_once('FilterLZW.php');
class FilterLZW_FPDI extends FilterLZW { class FilterLZW_FPDI extends FilterLZW {
var $fpdi; var $fpdi;
function FilterLZW_FPDI(&$fpdi) { function FilterLZW_FPDI(&$fpdi) {
$this->fpdi =& $fpdi; $this->fpdi =& $fpdi;
} }
function error($msg) { function error($msg) {
$this->fpdi->error($msg); $this->fpdi->error($msg);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
// //
// FPDF_TPL - Version 1.1.4 // FPDF_TPL - Version 1.1.5
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
@ -29,13 +29,13 @@ class FPDF_TPL extends FPDF {
* @var int * @var int
*/ */
var $tpl = 0; var $tpl = 0;
/** /**
* "In Template"-Flag * "In Template"-Flag
* @var boolean * @var boolean
*/ */
var $_intpl = false; var $_intpl = false;
/** /**
* Nameprefix of Templates used in Resources-Dictonary * Nameprefix of Templates used in Resources-Dictonary
* @var string A String defining the Prefix used as Template-Object-Names. Have to beginn with an / * @var string A String defining the Prefix used as Template-Object-Names. Have to beginn with an /
@ -47,14 +47,14 @@ class FPDF_TPL extends FPDF {
* @var array * @var array
*/ */
var $_res = array(); var $_res = array();
/** /**
* Last used Template data * Last used Template data
* *
* @var array * @var array
*/ */
var $lastUsedTemplateData = array(); var $lastUsedTemplateData = array();
/** /**
* Start a Template * Start a Template
* *
@ -107,7 +107,7 @@ class FPDF_TPL extends FPDF {
); );
$this->SetAutoPageBreak(false); $this->SetAutoPageBreak(false);
// Define own high and width to calculate possitions correct // Define own high and width to calculate possitions correct
$this->h = $h; $this->h = $h;
$this->w = $w; $this->w = $w;
@ -118,7 +118,7 @@ class FPDF_TPL extends FPDF {
return $this->tpl; return $this->tpl;
} }
/** /**
* End Template * End Template
* *
@ -128,7 +128,7 @@ class FPDF_TPL extends FPDF {
*/ */
function endTemplate() { function endTemplate() {
if ($this->_intpl) { if ($this->_intpl) {
$this->_intpl = false; $this->_intpl = false;
$tpl =& $this->tpls[$this->tpl]; $tpl =& $this->tpls[$this->tpl];
$this->SetXY($tpl['o_x'], $tpl['o_y']); $this->SetXY($tpl['o_x'], $tpl['o_y']);
$this->tMargin = $tpl['o_tMargin']; $this->tMargin = $tpl['o_tMargin'];
@ -137,13 +137,13 @@ class FPDF_TPL extends FPDF {
$this->h = $tpl['o_h']; $this->h = $tpl['o_h'];
$this->w = $tpl['o_w']; $this->w = $tpl['o_w'];
$this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']); $this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']);
return $this->tpl; return $this->tpl;
} else { } else {
return false; return false;
} }
} }
/** /**
* Use a Template in current Page or other Template * Use a Template in current Page or other Template
* *
@ -167,27 +167,27 @@ class FPDF_TPL extends FPDF {
if (!isset($this->tpls[$tplidx])) if (!isset($this->tpls[$tplidx]))
$this->error("Template does not exist!"); $this->error("Template does not exist!");
if ($this->_intpl) { if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx]; $this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
} }
$tpl =& $this->tpls[$tplidx]; $tpl =& $this->tpls[$tplidx];
$w = $tpl['w']; $w = $tpl['w'];
$h = $tpl['h']; $h = $tpl['h'];
if ($_x == null) if ($_x == null)
$_x = 0; $_x = 0;
if ($_y == null) if ($_y == null)
$_y = 0; $_y = 0;
$_x += $tpl['x']; $_x += $tpl['x'];
$_y += $tpl['y']; $_y += $tpl['y'];
$wh = $this->getTemplateSize($tplidx, $_w, $_h); $wh = $this->getTemplateSize($tplidx, $_w, $_h);
$_w = $wh['w']; $_w = $wh['w'];
$_h = $wh['h']; $_h = $wh['h'];
$tData = array( $tData = array(
'x' => $this->x, 'x' => $this->x,
'y' => $this->y, 'y' => $this->y,
@ -199,15 +199,15 @@ class FPDF_TPL extends FPDF {
'ty' => ($this->h-$_y-$_h), 'ty' => ($this->h-$_y-$_h),
'lty' => ($this->h-$_y-$_h) - ($this->h-$h) * ($_h/$h) 'lty' => ($this->h-$_y-$_h) - ($this->h-$h) * ($_h/$h)
); );
$this->_out(sprintf("q %.4F 0 0 %.4F %.4F %.4F cm", $tData['scaleX'], $tData['scaleY'], $tData['tx']*$this->k, $tData['ty']*$this->k)); // Translate $this->_out(sprintf("q %.4F 0 0 %.4F %.4F %.4F cm", $tData['scaleX'], $tData['scaleY'], $tData['tx']*$this->k, $tData['ty']*$this->k)); // Translate
$this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx)); $this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx));
$this->lastUsedTemplateData = $tData; $this->lastUsedTemplateData = $tData;
return array("w" => $_w, "h" => $_h); return array("w" => $_w, "h" => $_h);
} }
/** /**
* Get The calculated Size of a Template * Get The calculated Size of a Template
* *
@ -225,7 +225,7 @@ class FPDF_TPL extends FPDF {
$tpl =& $this->tpls[$tplidx]; $tpl =& $this->tpls[$tplidx];
$w = $tpl['w']; $w = $tpl['w'];
$h = $tpl['h']; $h = $tpl['h'];
if ($_w == 0 and $_h == 0) { if ($_w == 0 and $_h == 0) {
$_w = $w; $_w = $w;
$_h = $h; $_h = $h;
@ -235,10 +235,10 @@ class FPDF_TPL extends FPDF {
$_w = $_h*$w/$h; $_w = $_h*$w/$h;
if($_h==0) if($_h==0)
$_h = $_w*$h/$w; $_h = $_w*$h/$w;
return array("w" => $_w, "h" => $_h); return array("w" => $_w, "h" => $_h);
} }
/** /**
* See FPDF/TCPDF-Documentation ;-) * See FPDF/TCPDF-Documentation ;-)
*/ */
@ -251,43 +251,49 @@ class FPDF_TPL extends FPDF {
*/ */
if ($this->_intpl) if ($this->_intpl)
$this->FontFamily = ''; $this->FontFamily = '';
parent::SetFont($family, $style, $size, $fontfile); parent::SetFont($family, $style, $size, $fontfile);
$fontkey = $this->FontFamily.$this->FontStyle; $fontkey = $this->FontFamily.$this->FontStyle;
if ($this->_intpl) { if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
} else { } else {
$this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey]; $this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
} }
} }
/** /**
* See FPDF/TCPDF-Documentation ;-) * See FPDF/TCPDF-Documentation ;-)
*/ */
function Image($file, $x, $y, $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox = false, $hidden = false) { function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false) {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 7) { if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 7) {
$this->Error('More than 7 arguments for the Image method are only available in TCPDF.'); $this->Error('More than 7 arguments for the Image method are only available in TCPDF.');
} }
parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden); $ret = parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden, $fitonpage);
if ($this->_intpl) { if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
} else { } else {
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file]; $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
} }
return $ret;
} }
/** /**
* See FPDF-Documentation ;-) * See FPDF-Documentation ;-)
* *
* AddPage is not available when you're "in" a template. * AddPage is not available when you're "in" a template.
*/ */
function AddPage($orientation='', $format='') { function AddPage($orientation='', $format='', $keepmargins=false) {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 2) {
$this->Error('More than 2 arguments for the AddPage method are only available in TCPDF.');
}
if ($this->_intpl) if ($this->_intpl)
$this->Error('Adding pages in templates isn\'t possible!'); $this->Error('Adding pages in templates isn\'t possible!');
parent::AddPage($orientation, $format); parent::AddPage($orientation, $format, $keepmargins);
} }
/** /**
@ -297,24 +303,24 @@ class FPDF_TPL extends FPDF {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 5) { if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 5) {
$this->Error('More than 5 arguments for the Image method are only available in TCPDF.'); $this->Error('More than 5 arguments for the Image method are only available in TCPDF.');
} }
if ($this->_intpl) if ($this->_intpl)
$this->Error('Using links in templates aren\'t possible!'); $this->Error('Using links in templates aren\'t possible!');
parent::Link($x, $y, $w, $h, $link, $spaces); parent::Link($x, $y, $w, $h, $link, $spaces);
} }
function AddLink() { function AddLink() {
if ($this->_intpl) if ($this->_intpl)
$this->Error('Adding links in templates aren\'t possible!'); $this->Error('Adding links in templates aren\'t possible!');
return parent::AddLink(); return parent::AddLink();
} }
function SetLink($link, $y=0, $page=-1) { function SetLink($link, $y=0, $page=-1) {
if ($this->_intpl) if ($this->_intpl)
$this->Error('Setting links in templates aren\'t possible!'); $this->Error('Setting links in templates aren\'t possible!');
parent::SetLink($link, $y, $page); parent::SetLink($link, $y, $page);
} }
/** /**
* Private Method that writes the form xobjects * Private Method that writes the form xobjects
*/ */
@ -339,13 +345,13 @@ class FPDF_TPL extends FPDF {
// ury // ury
($tpl['h']-$tpl['y'])*$this->k ($tpl['h']-$tpl['y'])*$this->k
)); ));
if ($tpl['x'] != 0 || $tpl['y'] != 0) { if ($tpl['x'] != 0 || $tpl['y'] != 0) {
$this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]', $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',
-$tpl['x']*$this->k*2, $tpl['y']*$this->k*2 -$tpl['x']*$this->k*2, $tpl['y']*$this->k*2
)); ));
} }
$this->_out('/Resources '); $this->_out('/Resources ');
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
@ -355,7 +361,7 @@ class FPDF_TPL extends FPDF {
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
$this->_out('>>'); $this->_out('>>');
} }
if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) || if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
{ {
$this->_out('/XObject <<'); $this->_out('/XObject <<');
@ -370,13 +376,13 @@ class FPDF_TPL extends FPDF {
$this->_out('>>'); $this->_out('>>');
} }
$this->_out('>>'); $this->_out('>>');
$this->_out('/Length '.strlen($p).' >>'); $this->_out('/Length '.strlen($p).' >>');
$this->_putstream($p); $this->_putstream($p);
$this->_out('endobj'); $this->_out('endobj');
} }
} }
/** /**
* Overwritten to add _putformxobjects() after _putimages() * Overwritten to add _putformxobjects() after _putimages()
* *
@ -385,10 +391,10 @@ class FPDF_TPL extends FPDF {
parent::_putimages(); parent::_putimages();
$this->_putformxobjects(); $this->_putformxobjects();
} }
function _putxobjectdict() { function _putxobjectdict() {
parent::_putxobjectdict(); parent::_putxobjectdict();
if (count($this->tpls)) { if (count($this->tpls)) {
foreach($this->tpls as $tplidx => $tpl) { foreach($this->tpls as $tplidx => $tpl) {
$this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n'])); $this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n']));

View File

@ -1,6 +1,6 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
@ -17,8 +17,7 @@
// limitations under the License. // limitations under the License.
// //
define('FPDI_VERSION','1.3.2'); define('FPDI_VERSION','1.3.4');
/* Begin DOLCHANGE Added by Regis */ /* Begin DOLCHANGE Added by Regis */
// height of cell repect font height // height of cell repect font height
@ -88,9 +87,12 @@ class FPDI extends FPDF_TPL {
*/ */
var $lastUsedPageBox; var $lastUsedPageBox;
/**
* Cache for imported pages/template ids
* @var array
*/
var $_importedPages = array(); var $_importedPages = array();
/** /**
* Set a source-file * Set a source-file
* *
@ -99,7 +101,7 @@ class FPDI extends FPDF_TPL {
*/ */
function setSourceFile($filename) { function setSourceFile($filename) {
$this->current_filename = $filename; $this->current_filename = $filename;
$fn =& $this->current_filename; $fn = $this->current_filename;
if (!isset($this->parsers[$fn])) if (!isset($this->parsers[$fn]))
$this->parsers[$fn] = new fpdi_pdf_parser($fn, $this); $this->parsers[$fn] = new fpdi_pdf_parser($fn, $this);
@ -119,7 +121,7 @@ class FPDI extends FPDF_TPL {
return $this->error('Please import the desired pages before creating a new template.'); return $this->error('Please import the desired pages before creating a new template.');
} }
$fn =& $this->current_filename; $fn = $this->current_filename;
// check if page already imported // check if page already imported
$pageKey = $fn.((int)$pageno).$boxName; $pageKey = $fn.((int)$pageno).$boxName;
@ -193,14 +195,19 @@ class FPDI extends FPDF_TPL {
if ($adjustPageSize == true && is_null($_x) && is_null($_y)) { if ($adjustPageSize == true && is_null($_x) && is_null($_y)) {
$size = $this->getTemplateSize($tplidx, $_w, $_h); $size = $this->getTemplateSize($tplidx, $_w, $_h);
$format = array($size['w'], $size['h']); $format = array($size['w'], $size['h']);
if ($format[0]!=$this->CurPageFormat[0] || $format[1]!=$this->CurPageFormat[1]) { if (!is_subclass_of($this, 'TCPDF')) {
$this->w=$format[0]; if ($format[0] != $this->CurPageFormat[0] || $format[1] != $this->CurPageFormat[1]) {
$this->h=$format[1]; $this->w = $format[0];
$this->wPt=$this->w*$this->k; $this->h = $format[1];
$this->hPt=$this->h*$this->k; $this->wPt = $this->w*$this->k;
$this->PageBreakTrigger=$this->h-$this->bMargin; $this->hPt = $this->h*$this->k;
$this->CurPageFormat=$format; $this->PageBreakTrigger = $this->h-$this->bMargin;
$this->PageSizes[$this->page]=array($this->wPt, $this->hPt); $this->CurPageFormat = $format;
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
}
} else {
$this->setPageFormat($format, $format[0] > $format[1] ? 'L' : 'P');
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
@ -51,6 +51,22 @@ class FPDF extends TCPDF {
} }
} }
function _putstream($s) {
$this->_out($this->_getstream($s));
}
function _getxobjectdict() {
$out = parent::_getxobjectdict();
if (count($this->tpls)) {
foreach($this->tpls as $tplidx => $tpl) {
$out .= sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n']);
}
}
return $out;
}
/** /**
* Encryption of imported data by FPDI * Encryption of imported data by FPDI
* *

View File

@ -1,391 +1,398 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
require_once('pdf_parser.php'); require_once('pdf_parser.php');
class fpdi_pdf_parser extends pdf_parser { class fpdi_pdf_parser extends pdf_parser {
/** /**
* Pages * Pages
* Index beginns at 0 * Index beginns at 0
* *
* @var array * @var array
*/ */
var $pages; var $pages;
/** /**
* Page count * Page count
* @var integer * @var integer
*/ */
var $page_count; var $page_count;
/** /**
* actual page number * actual page number
* @var integer * @var integer
*/ */
var $pageno; var $pageno;
/** /**
* PDF Version of imported Document * PDF Version of imported Document
* @var string * @var string
*/ */
var $pdfVersion; var $pdfVersion;
/** /**
* FPDI Reference * FPDI Reference
* @var object * @var object
*/ */
var $fpdi; var $fpdi;
/** /**
* Available BoxTypes * Available BoxTypes
* *
* @var array * @var array
*/ */
var $availableBoxes = array('/MediaBox', '/CropBox', '/BleedBox', '/TrimBox', '/ArtBox'); var $availableBoxes = array('/MediaBox', '/CropBox', '/BleedBox', '/TrimBox', '/ArtBox');
/** /**
* Constructor * Constructor
* *
* @param string $filename Source-Filename * @param string $filename Source-Filename
* @param object $fpdi Object of type fpdi * @param object $fpdi Object of type fpdi
*/ */
function fpdi_pdf_parser($filename, &$fpdi) { function fpdi_pdf_parser($filename, &$fpdi) {
$this->fpdi =& $fpdi; $this->fpdi =& $fpdi;
parent::pdf_parser($filename); parent::pdf_parser($filename);
// resolve Pages-Dictonary // resolve Pages-Dictonary
$pages = $this->pdf_resolve_object($this->c, $this->root[1][1]['/Pages']); $pages = $this->pdf_resolve_object($this->c, $this->root[1][1]['/Pages']);
// Read pages // Read pages
$this->read_pages($this->c, $pages, $this->pages); $this->read_pages($this->c, $pages, $this->pages);
// count pages; // count pages;
$this->page_count = count($this->pages); $this->page_count = count($this->pages);
} }
/** /**
* Overwrite parent::error() * Overwrite parent::error()
* *
* @param string $msg Error-Message * @param string $msg Error-Message
*/ */
function error($msg) { function error($msg) {
$this->fpdi->error($msg); $this->fpdi->error($msg);
} }
/** /**
* Get pagecount from sourcefile * Get pagecount from sourcefile
* *
* @return int * @return int
*/ */
function getPageCount() { function getPageCount() {
return $this->page_count; return $this->page_count;
} }
/** /**
* Set pageno * Set pageno
* *
* @param int $pageno Pagenumber to use * @param int $pageno Pagenumber to use
*/ */
function setPageno($pageno) { function setPageno($pageno) {
$pageno = ((int) $pageno) - 1; $pageno = ((int) $pageno) - 1;
if ($pageno < 0 || $pageno >= $this->getPageCount()) { if ($pageno < 0 || $pageno >= $this->getPageCount()) {
$this->fpdi->error('Pagenumber is wrong!'); $this->fpdi->error('Pagenumber is wrong!');
} }
$this->pageno = $pageno; $this->pageno = $pageno;
} }
/** /**
* Get page-resources from current page * Get page-resources from current page
* *
* @return array * @return array
*/ */
function getPageResources() { function getPageResources() {
return $this->_getPageResources($this->pages[$this->pageno]); return $this->_getPageResources($this->pages[$this->pageno]);
} }
/** /**
* Get page-resources from /Page * Get page-resources from /Page
* *
* @param array $obj Array of pdf-data * @param array $obj Array of pdf-data
*/ */
function _getPageResources ($obj) { // $obj = /Page function _getPageResources ($obj) { // $obj = /Page
$obj = $this->pdf_resolve_object($this->c, $obj); $obj = $this->pdf_resolve_object($this->c, $obj);
// If the current object has a resources // If the current object has a resources
// dictionary associated with it, we use // dictionary associated with it, we use
// it. Otherwise, we move back to its // it. Otherwise, we move back to its
// parent object. // parent object.
if (isset ($obj[1][1]['/Resources'])) { if (isset ($obj[1][1]['/Resources'])) {
$res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Resources']); $res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Resources']);
if ($res[0] == PDF_TYPE_OBJECT) if ($res[0] == PDF_TYPE_OBJECT)
return $res[1]; return $res[1];
return $res; return $res;
} else { } else {
if (!isset ($obj[1][1]['/Parent'])) { if (!isset ($obj[1][1]['/Parent'])) {
return false; return false;
} else { } else {
$res = $this->_getPageResources($obj[1][1]['/Parent']); $res = $this->_getPageResources($obj[1][1]['/Parent']);
if ($res[0] == PDF_TYPE_OBJECT) if ($res[0] == PDF_TYPE_OBJECT)
return $res[1]; return $res[1];
return $res; return $res;
} }
} }
} }
/** /**
* Get content of current page * Get content of current page
* *
* If more /Contents is an array, the streams are concated * If more /Contents is an array, the streams are concated
* *
* @return string * @return string
*/ */
function getContent() { function getContent() {
$buffer = ''; $buffer = '';
if (isset($this->pages[$this->pageno][1][1]['/Contents'])) { if (isset($this->pages[$this->pageno][1][1]['/Contents'])) {
$contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']); $contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']);
foreach($contents AS $tmp_content) { foreach($contents AS $tmp_content) {
$buffer .= $this->_rebuildContentStream($tmp_content).' '; $buffer .= $this->_rebuildContentStream($tmp_content).' ';
} }
} }
return $buffer; return $buffer;
} }
/** /**
* Resolve all content-objects * Resolve all content-objects
* *
* @param array $content_ref * @param array $content_ref
* @return array * @return array
*/ */
function _getPageContent($content_ref) { function _getPageContent($content_ref) {
$contents = array(); $contents = array();
if ($content_ref[0] == PDF_TYPE_OBJREF) { if ($content_ref[0] == PDF_TYPE_OBJREF) {
$content = $this->pdf_resolve_object($this->c, $content_ref); $content = $this->pdf_resolve_object($this->c, $content_ref);
if ($content[1][0] == PDF_TYPE_ARRAY) { if ($content[1][0] == PDF_TYPE_ARRAY) {
$contents = $this->_getPageContent($content[1]); $contents = $this->_getPageContent($content[1]);
} else { } else {
$contents[] = $content; $contents[] = $content;
} }
} else if ($content_ref[0] == PDF_TYPE_ARRAY) { } else if ($content_ref[0] == PDF_TYPE_ARRAY) {
foreach ($content_ref[1] AS $tmp_content_ref) { foreach ($content_ref[1] AS $tmp_content_ref) {
$contents = array_merge($contents,$this->_getPageContent($tmp_content_ref)); $contents = array_merge($contents,$this->_getPageContent($tmp_content_ref));
} }
} }
return $contents; return $contents;
} }
/** /**
* Rebuild content-streams * Rebuild content-streams
* *
* @param array $obj * @param array $obj
* @return string * @return string
*/ */
function _rebuildContentStream($obj) { function _rebuildContentStream($obj) {
$filters = array(); $filters = array();
if (isset($obj[1][1]['/Filter'])) { if (isset($obj[1][1]['/Filter'])) {
$_filter = $obj[1][1]['/Filter']; $_filter = $obj[1][1]['/Filter'];
if ($_filter[0] == PDF_TYPE_TOKEN) { if ($_filter[0] == PDF_TYPE_OBJREF) {
$filters[] = $_filter; $tmpFilter = $this->pdf_resolve_object($this->c, $_filter);
} else if ($_filter[0] == PDF_TYPE_ARRAY) { $_filter = $tmpFilter[1];
$filters = $_filter[1]; }
}
} if ($_filter[0] == PDF_TYPE_TOKEN) {
$filters[] = $_filter;
$stream = $obj[2][1]; } else if ($_filter[0] == PDF_TYPE_ARRAY) {
$filters = $_filter[1];
foreach ($filters AS $_filter) { }
switch ($_filter[1]) { }
case '/FlateDecode':
if (function_exists('gzuncompress')) { $stream = $obj[2][1];
$stream = (strlen($stream) > 0) ? @gzuncompress($stream) : '';
} else { foreach ($filters AS $_filter) {
$this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1])); switch ($_filter[1]) {
} case '/FlateDecode':
if ($stream === false) { // $stream .= "\x0F\x0D"; // in an errorious stream this suffix could work
$this->error('Error while decompressing stream.'); if (function_exists('gzuncompress')) {
} $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : '';
break; } else {
case '/LZWDecode': $this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1]));
include_once('filters/FilterLZW_FPDI.php'); }
$decoder = new FilterLZW_FPDI($this->fpdi);
$stream = $decoder->decode($stream); if ($stream === false) {
break; $this->error('Error while decompressing stream.');
case '/ASCII85Decode': }
include_once('filters/FilterASCII85_FPDI.php'); break;
$decoder = new FilterASCII85_FPDI($this->fpdi); case '/LZWDecode':
$stream = $decoder->decode($stream); include_once('filters/FilterLZW_FPDI.php');
break; $decoder = new FilterLZW_FPDI($this->fpdi);
case null: $stream = $decoder->decode($stream);
$stream = $stream; break;
break; case '/ASCII85Decode':
default: include_once('filters/FilterASCII85_FPDI.php');
$this->error(sprintf('Unsupported Filter: %s',$_filter[1])); $decoder = new FilterASCII85_FPDI($this->fpdi);
} $stream = $decoder->decode($stream);
} break;
case null:
return $stream; $stream = $stream;
} break;
default:
$this->error(sprintf('Unsupported Filter: %s',$_filter[1]));
/** }
* Get a Box from a page }
* Arrayformat is same as used by fpdf_tpl
* return $stream;
* @param array $page a /Page }
* @param string $box_index Type of Box @see $availableBoxes
* @return array
*/ /**
function getPageBox($page, $box_index) { * Get a Box from a page
$page = $this->pdf_resolve_object($this->c,$page); * Arrayformat is same as used by fpdf_tpl
$box = null; *
if (isset($page[1][1][$box_index])) * @param array $page a /Page
$box =& $page[1][1][$box_index]; * @param string $box_index Type of Box @see $availableBoxes
* @return array
if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) { */
$tmp_box = $this->pdf_resolve_object($this->c,$box); function getPageBox($page, $box_index) {
$box = $tmp_box[1]; $page = $this->pdf_resolve_object($this->c,$page);
} $box = null;
if (isset($page[1][1][$box_index]))
if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) { $box =& $page[1][1][$box_index];
$b =& $box[1];
return array('x' => $b[0][1]/$this->fpdi->k, if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) {
'y' => $b[1][1]/$this->fpdi->k, $tmp_box = $this->pdf_resolve_object($this->c,$box);
'w' => abs($b[0][1]-$b[2][1])/$this->fpdi->k, $box = $tmp_box[1];
'h' => abs($b[1][1]-$b[3][1])/$this->fpdi->k, }
'llx' => min($b[0][1], $b[2][1])/$this->fpdi->k,
'lly' => min($b[1][1], $b[3][1])/$this->fpdi->k, if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) {
'urx' => max($b[0][1], $b[2][1])/$this->fpdi->k, $b =& $box[1];
'ury' => max($b[1][1], $b[3][1])/$this->fpdi->k, return array('x' => $b[0][1]/$this->fpdi->k,
); 'y' => $b[1][1]/$this->fpdi->k,
} else if (!isset ($page[1][1]['/Parent'])) { 'w' => abs($b[0][1]-$b[2][1])/$this->fpdi->k,
return false; 'h' => abs($b[1][1]-$b[3][1])/$this->fpdi->k,
} else { 'llx' => min($b[0][1], $b[2][1])/$this->fpdi->k,
return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index); 'lly' => min($b[1][1], $b[3][1])/$this->fpdi->k,
} 'urx' => max($b[0][1], $b[2][1])/$this->fpdi->k,
} 'ury' => max($b[1][1], $b[3][1])/$this->fpdi->k,
);
function getPageBoxes($pageno) { } else if (!isset ($page[1][1]['/Parent'])) {
return $this->_getPageBoxes($this->pages[$pageno-1]); return false;
} } else {
return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index);
/** }
* Get all Boxes from /Page }
*
* @param array a /Page function getPageBoxes($pageno) {
* @return array return $this->_getPageBoxes($this->pages[$pageno-1]);
*/ }
function _getPageBoxes($page) {
$boxes = array(); /**
* Get all Boxes from /Page
foreach($this->availableBoxes AS $box) { *
if ($_box = $this->getPageBox($page,$box)) { * @param array a /Page
$boxes[$box] = $_box; * @return array
} */
} function _getPageBoxes($page) {
$boxes = array();
return $boxes;
} foreach($this->availableBoxes AS $box) {
if ($_box = $this->getPageBox($page,$box)) {
/** $boxes[$box] = $_box;
* Get the page rotation by pageno }
* }
* @param integer $pageno
* @return array return $boxes;
*/ }
function getPageRotation($pageno) {
return $this->_getPageRotation($this->pages[$pageno-1]); /**
} * Get the page rotation by pageno
*
function _getPageRotation ($obj) { // $obj = /Page * @param integer $pageno
$obj = $this->pdf_resolve_object($this->c, $obj); * @return array
if (isset ($obj[1][1]['/Rotate'])) { */
$res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']); function getPageRotation($pageno) {
if ($res[0] == PDF_TYPE_OBJECT) return $this->_getPageRotation($this->pages[$pageno-1]);
return $res[1]; }
return $res;
} else { function _getPageRotation ($obj) { // $obj = /Page
if (!isset ($obj[1][1]['/Parent'])) { $obj = $this->pdf_resolve_object($this->c, $obj);
return false; if (isset ($obj[1][1]['/Rotate'])) {
} else { $res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']);
$res = $this->_getPageRotation($obj[1][1]['/Parent']); if ($res[0] == PDF_TYPE_OBJECT)
if ($res[0] == PDF_TYPE_OBJECT) return $res[1];
return $res[1]; return $res;
return $res; } else {
} if (!isset ($obj[1][1]['/Parent'])) {
} return false;
} } else {
$res = $this->_getPageRotation($obj[1][1]['/Parent']);
/** if ($res[0] == PDF_TYPE_OBJECT)
* Read all /Page(es) return $res[1];
* return $res;
* @param object pdf_context }
* @param array /Pages }
* @param array the result-array }
*/
function read_pages (&$c, &$pages, &$result) { /**
// Get the kids dictionary * Read all /Page(es)
$_kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); *
* @param object pdf_context
if (!is_array($_kids)) * @param array /Pages
$this->error('Cannot find /Kids in current /Page-Dictionary'); * @param array the result-array
*/
if ($_kids[1][0] == PDF_TYPE_ARRAY) { function read_pages (&$c, &$pages, &$result) {
$kids = $_kids[1][1]; // Get the kids dictionary
} else { $_kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']);
$kids = $_kids[1];
} if (!is_array($_kids))
$this->error('Cannot find /Kids in current /Page-Dictionary');
foreach ($kids as $v) {
$pg = $this->pdf_resolve_object ($c, $v); if ($_kids[1][0] == PDF_TYPE_ARRAY) {
if ($pg[1][1]['/Type'][1] === '/Pages') { $kids = $_kids[1][1];
// If one of the kids is an embedded } else {
// /Pages array, resolve it as well. $kids = $_kids[1];
$this->read_pages ($c, $pg, $result); }
} else {
$result[] = $pg; foreach ($kids as $v) {
} $pg = $this->pdf_resolve_object ($c, $v);
} if ($pg[1][1]['/Type'][1] === '/Pages') {
} // If one of the kids is an embedded
// /Pages array, resolve it as well.
$this->read_pages ($c, $pg, $result);
} else {
/** $result[] = $pg;
* Get PDF-Version }
* }
* And reset the PDF Version used in FPDI if needed }
*/
function getPDFVersion() {
parent::getPDFVersion();
$this->fpdi->PDFVersion = max($this->fpdi->PDFVersion, $this->pdfVersion); /**
} * Get PDF-Version
*
* And reset the PDF Version used in FPDI if needed
*/
function getPDFVersion() {
parent::getPDFVersion();
$this->fpdi->PDFVersion = max($this->fpdi->PDFVersion, $this->pdfVersion);
}
} }

View File

@ -20,7 +20,7 @@
require_once('fpdi.php'); require_once('fpdi.php');
class FPDI_Protection extends FPDI { class FPDI_Protection extends FPDI {
var $encrypted = false; //whether document is protected var $encrypted = false; //whether document is protected
var $Uvalue; //U entry in pdf document var $Uvalue; //U entry in pdf document
var $Ovalue; //O entry in pdf document var $Ovalue; //O entry in pdf document
@ -29,21 +29,7 @@ class FPDI_Protection extends FPDI {
var $last_rc4_key = ''; //last RC4 key encrypted (cached for optimisation) var $last_rc4_key = ''; //last RC4 key encrypted (cached for optimisation)
var $last_rc4_key_c; //last RC4 computed key var $last_rc4_key_c; //last RC4 computed key
var $padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; var $padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
// DOL_CHANGE
/*
function FPDI_Protection($orientation='P',$unit='mm',$format='A4')
{
parent::FPDI($orientation,$unit,$format);
$this->_current_obj_id =& $this->current_obj_id; // for FPDI 1.1 compatibility
$this->encrypted=false;
$this->last_rc4_key = '';
$this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
"\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
}
*/
/** /**
* Function to set permissions as well as user and owner passwords * Function to set permissions as well as user and owner passwords
* *
@ -169,7 +155,7 @@ class FPDI_Protection extends FPDI {
return $out; return $out;
} }
/** /**
* Get MD5 as binary string * Get MD5 as binary string
@ -214,7 +200,7 @@ class FPDI_Protection extends FPDI {
$this->Pvalue = -(($protection^255)+1); $this->Pvalue = -(($protection^255)+1);
} }
function pdf_write_value(&$value) { function pdf_write_value(&$value) {
switch ($value[0]) { switch ($value[0]) {
case PDF_TYPE_STRING : case PDF_TYPE_STRING :
@ -222,39 +208,39 @@ class FPDI_Protection extends FPDI {
$value[1] = $this->_unescape($value[1]); $value[1] = $this->_unescape($value[1]);
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
$value[1] = $this->_escape($value[1]); $value[1] = $this->_escape($value[1]);
} }
break; break;
case PDF_TYPE_STREAM : case PDF_TYPE_STREAM :
if ($this->encrypted) { if ($this->encrypted) {
$value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]); $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
} }
break; break;
case PDF_TYPE_HEX : case PDF_TYPE_HEX :
if ($this->encrypted) { if ($this->encrypted) {
$value[1] = $this->hex2str($value[1]); $value[1] = $this->hex2str($value[1]);
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
// remake hexstring of encrypted string // remake hexstring of encrypted string
$value[1] = $this->str2hex($value[1]); $value[1] = $this->str2hex($value[1]);
} }
break; break;
} }
parent::pdf_write_value($value); parent::pdf_write_value($value);
} }
function hex2str($hex) { function hex2str($hex) {
return pack('H*', str_replace(array("\r","\n",' '),'', $hex)); return pack('H*', str_replace(array("\r","\n",' '),'', $hex));
} }
function str2hex($str) { function str2hex($str) {
return current(unpack('H*',$str)); return current(unpack('H*',$str));
} }
/** /**
* Deescape special characters * Deescape special characters
*/ */
@ -296,17 +282,17 @@ class FPDI_Protection extends FPDI {
if (ord($s[$count]) >= ord('0') && if (ord($s[$count]) >= ord('0') &&
ord($s[$count]) <= ord('9')) { ord($s[$count]) <= ord('9')) {
$oct = ''. $s[$count]; $oct = ''. $s[$count];
if (ord($s[$count+1]) >= ord('0') && if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) { ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count]; $oct .= $s[++$count];
if (ord($s[$count+1]) >= ord('0') && if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) { ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count]; $oct .= $s[++$count];
} }
} }
$out .= chr(octdec($oct)); $out .= chr(octdec($oct));
} else { } else {
$out .= $s[$count]; $out .= $s[$count];

View File

@ -1,103 +1,103 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.3.4
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
$__tmp = version_compare(phpversion(), "5") == -1 ? array('pdf_context') : array('pdf_context', false); $__tmp = version_compare(phpversion(), "5") == -1 ? array('pdf_context') : array('pdf_context', false);
if (!call_user_func_array('class_exists', $__tmp)) { if (!call_user_func_array('class_exists', $__tmp)) {
class pdf_context { class pdf_context {
/** /**
* Modi * Modi
* *
* @var integer 0 = file | 1 = string * @var integer 0 = file | 1 = string
*/ */
var $_mode = 0; var $_mode = 0;
var $file; var $file;
var $buffer; var $buffer;
var $offset; var $offset;
var $length; var $length;
var $stack; var $stack;
// Constructor // Constructor
function pdf_context(&$f) { function pdf_context(&$f) {
$this->file =& $f; $this->file =& $f;
if (is_string($this->file)) if (is_string($this->file))
$this->_mode = 1; $this->_mode = 1;
$this->reset(); $this->reset();
} }
// Optionally move the file // Optionally move the file
// pointer to a new location // pointer to a new location
// and reset the buffered data // and reset the buffered data
function reset($pos = null, $l = 100) { function reset($pos = null, $l = 100) {
if ($this->_mode == 0) { if ($this->_mode == 0) {
if (!is_null ($pos)) { if (!is_null ($pos)) {
fseek ($this->file, $pos); fseek ($this->file, $pos);
} }
$this->buffer = $l > 0 ? fread($this->file, $l) : ''; $this->buffer = $l > 0 ? fread($this->file, $l) : '';
$this->length = strlen($this->buffer); $this->length = strlen($this->buffer);
if ($this->length < $l) if ($this->length < $l)
$this->increase_length($l - $this->length); $this->increase_length($l - $this->length);
} else { } else {
$this->buffer = $this->file; $this->buffer = $this->file;
$this->length = strlen($this->buffer); $this->length = strlen($this->buffer);
} }
$this->offset = 0; $this->offset = 0;
$this->stack = array(); $this->stack = array();
} }
// Make sure that there is at least one // Make sure that there is at least one
// character beyond the current offset in // character beyond the current offset in
// the buffer to prevent the tokenizer // the buffer to prevent the tokenizer
// from attempting to access data that does // from attempting to access data that does
// not exist // not exist
function ensure_content() { function ensure_content() {
if ($this->offset >= $this->length - 1) { if ($this->offset >= $this->length - 1) {
return $this->increase_length(); return $this->increase_length();
} else { } else {
return true; return true;
} }
} }
// Forcefully read more data into the buffer // Forcefully read more data into the buffer
function increase_length($l=100) { function increase_length($l=100) {
if ($this->_mode == 0 && feof($this->file)) { if ($this->_mode == 0 && feof($this->file)) {
return false; return false;
} else if ($this->_mode == 0) { } else if ($this->_mode == 0) {
$totalLength = $this->length + $l; $totalLength = $this->length + $l;
do { do {
$this->buffer .= fread($this->file, $totalLength-$this->length); $this->buffer .= fread($this->file, $totalLength-$this->length);
} while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
return true; return true;
} else { } else {
return false; return false;
} }
} }
} }
} }
unset($__tmp); unset($__tmp);

File diff suppressed because it is too large Load Diff

View File

@ -1,70 +0,0 @@
<?php
//
// FPDI - Version 1.2.1
//
// Copyright 2004-2008 Setasign - Jan Slabon
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
if (!defined("PHP_VER_LOWER43"))
define("PHP_VER_LOWER43", version_compare(PHP_VERSION, "4.3", "<"));
/**
* ensure that strspn works correct if php-version < 4.3
*/
function _strspn($str1, $str2, $start=null, $length=null) {
$numargs = func_num_args();
if (PHP_VER_LOWER43 == 1) {
if (isset($length)) {
$str1 = substr($str1, $start, $length);
} else {
$str1 = substr($str1, $start);
}
}
if ($numargs == 2 || PHP_VER_LOWER43 == 1) {
return strspn($str1, $str2);
} else if ($numargs == 3) {
return strspn($str1, $str2, $start);
} else {
return strspn($str1, $str2, $start, $length);
}
}
/**
* ensure that strcspn works correct if php-version < 4.3
*/
function _strcspn($str1, $str2, $start=null, $length=null) {
$numargs = func_num_args();
if (PHP_VER_LOWER43 == 1) {
if (isset($length)) {
$str1 = substr($str1, $start, $length);
} else {
$str1 = substr($str1, $start);
}
}
if ($numargs == 2 || PHP_VER_LOWER43 == 1) {
return strcspn($str1, $str2);
} else if ($numargs == 3) {
return strcspn($str1, $str2, $start);
} else {
return strcspn($str1, $str2, $start, $length);
}
}