Qual: update fpdi libraries:

FPDF_TPL v1.1.4
FPDI v1.3.2
FPDI_Protection v1.0.3
This commit is contained in:
Regis Houssin 2010-03-03 09:13:45 +00:00
parent 3605390156
commit 925ead825c
14 changed files with 2829 additions and 2590 deletions

View File

@ -14,10 +14,10 @@ ArtiChow 1.07 Public Domain Yes Graphics
Php-barcode 0.3pl1 GPL 2.0 Yes Bar code generation Php-barcode 0.3pl1 GPL 2.0 Yes Bar code generation
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.53 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.2 Apache Software License 2.0 No GPL3 only PDF templates management FPDF_TPL 1.1.4 Apache Software License 2.0 No GPL3 only PDF templates management
FPDI 1.2.1 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_Protection 1.0.2 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 4.6.2 LGPL 3.0 Yes Iphone templates framework iWebkit 4.6.2 LGPL 3.0 Yes Iphone templates framework
JCrop 0.9.8 MIT Licence Yes JS library to crop images JCrop 0.9.8 MIT Licence Yes JS library to crop images

View File

@ -1,95 +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("ORD_z"))
define("ORD_z",ord('z'));
if (!defined("ORD_exclmark"))
define("ORD_exclmark", ord('!'));
if (!defined("ORD_u"))
define("ORD_u", ord("u"));
if (!defined("ORD_tilde"))
define("ORD_tilde", ord('~'));
class ASCII85Decode {
function ASCII85Decode(&$fpdi) {
$this->fpdi =& $fpdi;
}
function decode($in) {
$out = "";
$state = 0;
$chn = null;
$l = strlen($in);
for ($k = 0; $k < $l; ++$k) {
$ch = ord($in[$k]) & 0xff;
if ($ch == ORD_tilde) {
break;
}
if (preg_match("/^\s$/",chr($ch))) {
continue;
}
if ($ch == ORD_z && $state == 0) {
$out .= chr(0).chr(0).chr(0).chr(0);
continue;
}
if ($ch < ORD_exclmark || $ch > ORD_u) {
$this->fpdi->error("Illegal character in ASCII85Decode.");
}
$chn[$state++] = $ch - ORD_exclmark;
if ($state == 5) {
$state = 0;
$r = 0;
for ($j = 0; $j < 5; ++$j)
$r = $r * 85 + $chn[$j];
$out .= chr($r >> 24);
$out .= chr($r >> 16);
$out .= chr($r >> 8);
$out .= chr($r);
}
}
$r = 0;
if ($state == 1)
$this->fpdi->error("Illegal length in ASCII85Decode.");
if ($state == 2) {
$r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
$out .= chr($r >> 24);
}
else if ($state == 3) {
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2]+1) * 85 * 85;
$out .= chr($r >> 24);
$out .= chr($r >> 16);
}
else if ($state == 4) {
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3]+1) * 85 ;
$out .= chr($r >> 24);
$out .= chr($r >> 16);
$out .= chr($r >> 8);
}
return $out;
}
}

View File

@ -1,147 +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.
//
class LZWDecode {
var $sTable = array();
var $data = null;
var $tIdx;
var $bitsToGet = 9;
var $bytePointer;
var $bitPointer;
var $nextData = 0;
var $nextBits = 0;
var $andTable = array(511, 1023, 2047, 4095);
function LZWDecode(&$fpdi) {
$this->fpdi =& $fpdi;
}
/**
* Method to decode LZW compressed data.
*
* @param string data The compressed data.
*/
function decode($data) {
if($data[0] == 0x00 && $data[1] == 0x01) {
$this->fpdi->error("LZW flavour not supported.");
}
$this->initsTable();
$this->data = $data;
// Initialize pointers
$this->bytePointer = 0;
$this->bitPointer = 0;
$this->nextData = 0;
$this->nextBits = 0;
$oldCode = 0;
$string = "";
$uncompData = "";
while (($code = $this->getNextCode()) != 257) {
if ($code == 256) {
$this->initsTable();
$code = $this->getNextCode();
if ($code == 257) {
break;
}
$uncompData .= $this->sTable[$code];
$oldCode = $code;
} else {
if ($code < $this->tIdx) {
$string = $this->sTable[$code];
$uncompData .= $string;
$this->addStringToTable($this->sTable[$oldCode], $string[0]);
$oldCode = $code;
} else {
$string = $this->sTable[$oldCode];
$string = $string.$string[0];
$uncompData .= $string;
$this->addStringToTable($string);
$oldCode = $code;
}
}
}
return $uncompData;
}
/**
* Initialize the string table.
*/
function initsTable() {
$this->sTable = array();
for ($i = 0; $i < 256; $i++)
$this->sTable[$i] = chr($i);
$this->tIdx = 258;
$this->bitsToGet = 9;
}
/**
* Add a new string to the string table.
*/
function addStringToTable ($oldString, $newString="") {
$string = $oldString.$newString;
// Add this new String to the table
$this->sTable[$this->tIdx++] = $string;
if ($this->tIdx == 511) {
$this->bitsToGet = 10;
} else if ($this->tIdx == 1023) {
$this->bitsToGet = 11;
} else if ($this->tIdx == 2047) {
$this->bitsToGet = 12;
}
}
// Returns the next 9, 10, 11 or 12 bits
function getNextCode() {
if ($this->bytePointer == strlen($this->data))
return 257;
$this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff);
$this->nextBits += 8;
if ($this->nextBits < $this->bitsToGet) {
$this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff);
$this->nextBits += 8;
}
$code = ($this->nextData >> ($this->nextBits - $this->bitsToGet)) & $this->andTable[$this->bitsToGet-9];
$this->nextBits -= $this->bitsToGet;
return $code;
}
}

View File

@ -0,0 +1,104 @@
<?php
//
// FPDI - Version 1.3.2
//
// Copyright 2004-2010 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('ORD_z'))
define('ORD_z',ord('z'));
if (!defined('ORD_exclmark'))
define('ORD_exclmark', ord('!'));
if (!defined('ORD_u'))
define('ORD_u', ord('u'));
if (!defined('ORD_tilde'))
define('ORD_tilde', ord('~'));
$__tmp = version_compare(phpversion(), "5") == -1 ? array('FilterASCII85') : array('FilterASCII85', false);
if (!call_user_func_array('class_exists', $__tmp)) {
class FilterASCII85 {
function error($msg) {
die($msg);
}
function decode($in) {
$out = '';
$state = 0;
$chn = null;
$l = strlen($in);
for ($k = 0; $k < $l; ++$k) {
$ch = ord($in[$k]) & 0xff;
if ($ch == ORD_tilde) {
break;
}
if (preg_match('/^\s$/',chr($ch))) {
continue;
}
if ($ch == ORD_z && $state == 0) {
$out .= chr(0).chr(0).chr(0).chr(0);
continue;
}
if ($ch < ORD_exclmark || $ch > ORD_u) {
return $this->error('Illegal character in ASCII85Decode.');
}
$chn[$state++] = $ch - ORD_exclmark;
if ($state == 5) {
$state = 0;
$r = 0;
for ($j = 0; $j < 5; ++$j)
$r = $r * 85 + $chn[$j];
$out .= chr($r >> 24);
$out .= chr($r >> 16);
$out .= chr($r >> 8);
$out .= chr($r);
}
}
$r = 0;
if ($state == 1)
return $this->error('Illegal length in ASCII85Decode.');
if ($state == 2) {
$r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
$out .= chr($r >> 24);
}
else if ($state == 3) {
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2]+1) * 85 * 85;
$out .= chr($r >> 24);
$out .= chr($r >> 16);
}
else if ($state == 4) {
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3]+1) * 85 ;
$out .= chr($r >> 24);
$out .= chr($r >> 16);
$out .= chr($r >> 8);
}
return $out;
}
function encode($in) {
return $this->error("ASCII85 encoding not implemented.");
}
}
}
unset($__tmp);

View File

@ -0,0 +1,33 @@
<?php
//
// FPDI - Version 1.3.2
//
// Copyright 2004-2010 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.
//
require_once('FilterASCII85.php');
class FilterASCII85_FPDI extends FilterASCII85 {
var $fpdi;
function FPDI_FilterASCII85(&$fpdi) {
$this->fpdi =& $fpdi;
}
function error($msg) {
$this->fpdi->error($msg);
}
}

View File

@ -0,0 +1,160 @@
<?php
//
// FPDI - Version 1.3.2
//
// Copyright 2004-2010 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.
//
$__tmp = version_compare(phpversion(), "5") == -1 ? array('FilterLZW') : array('FilterLZW', false);
if (!call_user_func_array('class_exists', $__tmp)) {
class FilterLZW {
var $sTable = array();
var $data = null;
var $dataLength = 0;
var $tIdx;
var $bitsToGet = 9;
var $bytePointer;
var $bitPointer;
var $nextData = 0;
var $nextBits = 0;
var $andTable = array(511, 1023, 2047, 4095);
function error($msg) {
die($msg);
}
/**
* Method to decode LZW compressed data.
*
* @param string data The compressed data.
*/
function decode($data) {
if($data[0] == 0x00 && $data[1] == 0x01) {
$this->error('LZW flavour not supported.');
}
$this->initsTable();
$this->data = $data;
$this->dataLength = strlen($data);
// Initialize pointers
$this->bytePointer = 0;
$this->bitPointer = 0;
$this->nextData = 0;
$this->nextBits = 0;
$oldCode = 0;
$string = '';
$uncompData = '';
while (($code = $this->getNextCode()) != 257) {
if ($code == 256) {
$this->initsTable();
$code = $this->getNextCode();
if ($code == 257) {
break;
}
$uncompData .= $this->sTable[$code];
$oldCode = $code;
} else {
if ($code < $this->tIdx) {
$string = $this->sTable[$code];
$uncompData .= $string;
$this->addStringToTable($this->sTable[$oldCode], $string[0]);
$oldCode = $code;
} else {
$string = $this->sTable[$oldCode];
$string = $string.$string[0];
$uncompData .= $string;
$this->addStringToTable($string);
$oldCode = $code;
}
}
}
return $uncompData;
}
/**
* Initialize the string table.
*/
function initsTable() {
$this->sTable = array();
for ($i = 0; $i < 256; $i++)
$this->sTable[$i] = chr($i);
$this->tIdx = 258;
$this->bitsToGet = 9;
}
/**
* Add a new string to the string table.
*/
function addStringToTable ($oldString, $newString='') {
$string = $oldString.$newString;
// Add this new String to the table
$this->sTable[$this->tIdx++] = $string;
if ($this->tIdx == 511) {
$this->bitsToGet = 10;
} else if ($this->tIdx == 1023) {
$this->bitsToGet = 11;
} else if ($this->tIdx == 2047) {
$this->bitsToGet = 12;
}
}
// Returns the next 9, 10, 11 or 12 bits
function getNextCode() {
if ($this->bytePointer == $this->dataLength) {
return 257;
}
$this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff);
$this->nextBits += 8;
if ($this->nextBits < $this->bitsToGet) {
$this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff);
$this->nextBits += 8;
}
$code = ($this->nextData >> ($this->nextBits - $this->bitsToGet)) & $this->andTable[$this->bitsToGet-9];
$this->nextBits -= $this->bitsToGet;
return $code;
}
function encode($in) {
$this->error("LZW encoding not implemented.");
}
}
}
unset($__tmp);

View File

@ -0,0 +1,33 @@
<?php
//
// FPDI - Version 1.3.2
//
// Copyright 2004-2010 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.
//
require_once('FilterLZW.php');
class FilterLZW_FPDI extends FilterLZW {
var $fpdi;
function FilterLZW_FPDI(&$fpdi) {
$this->fpdi =& $fpdi;
}
function error($msg) {
$this->fpdi->error($msg);
}
}

View File

@ -1,402 +1,412 @@
<?php <?php
// //
// FPDF_TPL - Version 1.1.2 // FPDF_TPL - Version 1.1.4
// //
// Copyright 2004-2008 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.
// //
// DOLCHANGE // DOLCHANGE
require_once(FPDF_PATH."fpdf.php"); require_once(FPDF_PATH."fpdf.php");
//require_once('E:/Mes Developpements/dolibarr/htdocs/includes/fpdf/fpdf/fpdf.php');
//require_once('C:/temp/16/fpdf.php'); class FPDF_TPL extends FPDF {
/**
class FPDF_TPL extends FPDF { * Array of Tpl-Data
/** * @var array
* Array of Tpl-Data */
* @var array var $tpls = array();
*/
var $tpls = array(); /**
* Current Template-ID
/** * @var int
* Current Template-ID */
* @var int var $tpl = 0;
*/
var $tpl = 0; /**
* "In Template"-Flag
/** * @var boolean
* "In Template"-Flag */
* @var boolean var $_intpl = false;
*/
var $_intpl = false; /**
* Nameprefix of Templates used in Resources-Dictonary
/** * @var string A String defining the Prefix used as Template-Object-Names. Have to beginn with an /
* 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 $tplprefix = "/TPL";
*/
var $tplprefix = "/TPL"; /**
* Resources used By Templates and Pages
/** * @var array
* Resources used By Templates and Pages */
* @var array var $_res = array();
*/
var $_res = array(); /**
* Last used Template data
/** *
* Start a Template * @var array
* */
* This method starts a template. You can give own coordinates to build an own sized var $lastUsedTemplateData = array();
* Template. Pay attention, that the margins are adapted to the new templatesize.
* If you want to write outside the template, for example to build a clipped Template, /**
* you have to set the Margins and "Cursor"-Position manual after beginTemplate-Call. * Start a Template
* *
* If no parameter is given, the template uses the current page-size. * This method starts a template. You can give own coordinates to build an own sized
* The Method returns an ID of the current Template. This ID is used later for using this template. * Template. Pay attention, that the margins are adapted to the new templatesize.
* Warning: A created Template is used in PDF at all events. Still if you don't use it after creation! * If you want to write outside the template, for example to build a clipped Template,
* * you have to set the Margins and "Cursor"-Position manual after beginTemplate-Call.
* @param int $x The x-coordinate given in user-unit *
* @param int $y The y-coordinate given in user-unit * If no parameter is given, the template uses the current page-size.
* @param int $w The width given in user-unit * The Method returns an ID of the current Template. This ID is used later for using this template.
* @param int $h The height given in user-unit * Warning: A created Template is used in PDF at all events. Still if you don't use it after creation!
* @return int The ID of new created Template *
*/ * @param int $x The x-coordinate given in user-unit
function beginTemplate($x=null, $y=null, $w=null, $h=null) { * @param int $y The y-coordinate given in user-unit
if ($this->page <= 0) * @param int $w The width given in user-unit
$this->error("You have to add a page to fpdf first!"); * @param int $h The height given in user-unit
* @return int The ID of new created Template
if ($x == null) */
$x = 0; function beginTemplate($x=null, $y=null, $w=null, $h=null) {
if ($y == null) if ($this->page <= 0)
$y = 0; $this->error("You have to add a page to fpdf first!");
if ($w == null)
$w = $this->w; if ($x == null)
if ($h == null) $x = 0;
$h = $this->h; if ($y == null)
$y = 0;
// Save settings if ($w == null)
$this->tpl++; $w = $this->w;
$tpl =& $this->tpls[$this->tpl]; if ($h == null)
$tpl = array( $h = $this->h;
'o_x' => $this->x,
'o_y' => $this->y, // Save settings
'o_AutoPageBreak' => $this->AutoPageBreak, $this->tpl++;
'o_bMargin' => $this->bMargin, $tpl =& $this->tpls[$this->tpl];
'o_tMargin' => $this->tMargin, $tpl = array(
'o_lMargin' => $this->lMargin, 'o_x' => $this->x,
'o_rMargin' => $this->rMargin, 'o_y' => $this->y,
'o_h' => $this->h, 'o_AutoPageBreak' => $this->AutoPageBreak,
'o_w' => $this->w, 'o_bMargin' => $this->bMargin,
'buffer' => '', 'o_tMargin' => $this->tMargin,
'x' => $x, 'o_lMargin' => $this->lMargin,
'y' => $y, 'o_rMargin' => $this->rMargin,
'w' => $w, 'o_h' => $this->h,
'h' => $h 'o_w' => $this->w,
); 'buffer' => '',
'x' => $x,
$this->SetAutoPageBreak(false); 'y' => $y,
'w' => $w,
// Define own high and width to calculate possitions correct 'h' => $h
$this->h = $h; );
$this->w = $w;
$this->SetAutoPageBreak(false);
$this->_intpl = true;
$this->SetXY($x+$this->lMargin, $y+$this->tMargin); // Define own high and width to calculate possitions correct
$this->SetRightMargin($this->w-$w+$this->rMargin); $this->h = $h;
$this->w = $w;
return $this->tpl;
} $this->_intpl = true;
$this->SetXY($x+$this->lMargin, $y+$this->tMargin);
/** $this->SetRightMargin($this->w-$w+$this->rMargin);
* End Template
* return $this->tpl;
* This method ends a template and reset initiated variables on beginTemplate. }
*
* @return mixed If a template is opened, the ID is returned. If not a false is returned. /**
*/ * End Template
function endTemplate() { *
if ($this->_intpl) { * This method ends a template and reset initiated variables on beginTemplate.
$this->_intpl = false; *
$tpl =& $this->tpls[$this->tpl]; * @return mixed If a template is opened, the ID is returned. If not a false is returned.
$this->SetXY($tpl['o_x'], $tpl['o_y']); */
$this->tMargin = $tpl['o_tMargin']; function endTemplate() {
$this->lMargin = $tpl['o_lMargin']; if ($this->_intpl) {
$this->rMargin = $tpl['o_rMargin']; $this->_intpl = false;
$this->h = $tpl['o_h']; $tpl =& $this->tpls[$this->tpl];
$this->w = $tpl['o_w']; $this->SetXY($tpl['o_x'], $tpl['o_y']);
$this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']); $this->tMargin = $tpl['o_tMargin'];
$this->lMargin = $tpl['o_lMargin'];
return $this->tpl; $this->rMargin = $tpl['o_rMargin'];
} else { $this->h = $tpl['o_h'];
return false; $this->w = $tpl['o_w'];
} $this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']);
}
return $this->tpl;
/** } else {
* Use a Template in current Page or other Template return false;
* }
* You can use a template in a page or in another template. }
* You can give the used template a new size like you use the Image()-method.
* All parameters are optional. The width or height is calculated automaticaly /**
* if one is given. If no parameter is given the origin size as defined in * Use a Template in current Page or other Template
* beginTemplate() is used. *
* The calculated or used width and height are returned as an array. * You can use a template in a page or in another template.
* * You can give the used template a new size like you use the Image()-method.
* @param int $tplidx A valid template-Id * All parameters are optional. The width or height is calculated automaticaly
* @param int $_x The x-position * if one is given. If no parameter is given the origin size as defined in
* @param int $_y The y-position * beginTemplate() is used.
* @param int $_w The new width of the template * The calculated or used width and height are returned as an array.
* @param int $_h The new height of the template *
* @retrun array The height and width of the template * @param int $tplidx A valid template-Id
*/ * @param int $_x The x-position
function useTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) { * @param int $_y The y-position
if ($this->page <= 0) * @param int $_w The new width of the template
$this->error("You have to add a page to fpdf first!"); * @param int $_h The new height of the template
* @retrun array The height and width of the template
if (!isset($this->tpls[$tplidx])) */
$this->error("Template does not exist!"); function useTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
if ($this->page <= 0)
if ($this->_intpl) { $this->error("You have to add a page to fpdf first!");
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
} if (!isset($this->tpls[$tplidx]))
$this->error("Template does not exist!");
$tpl =& $this->tpls[$tplidx];
$x = $tpl['x']; if ($this->_intpl) {
$y = $tpl['y']; $this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
$w = $tpl['w']; }
$h = $tpl['h'];
$tpl =& $this->tpls[$tplidx];
if ($_x == null) $w = $tpl['w'];
$_x = $x; $h = $tpl['h'];
if ($_y == null)
$_y = $y; if ($_x == null)
$wh = $this->getTemplateSize($tplidx, $_w, $_h); $_x = 0;
$_w = $wh['w']; if ($_y == null)
$_h = $wh['h']; $_y = 0;
$this->_out(sprintf("q %.4F 0 0 %.4F %.2F %.2F cm", ($_w/$w), ($_h/$h), $_x*$this->k, ($this->h-($_y+$_h))*$this->k)); // Translate $_x += $tpl['x'];
$this->_out($this->tplprefix.$tplidx." Do Q"); $_y += $tpl['y'];
return array("w" => $_w, "h" => $_h); $wh = $this->getTemplateSize($tplidx, $_w, $_h);
} $_w = $wh['w'];
$_h = $wh['h'];
/**
* Get The calculated Size of a Template $tData = array(
* 'x' => $this->x,
* If one size is given, this method calculates the other one. 'y' => $this->y,
* 'w' => $_w,
* @param int $tplidx A valid template-Id 'h' => $_h,
* @param int $_w The width of the template 'scaleX' => ($_w/$w),
* @param int $_h The height of the template 'scaleY' => ($_h/$h),
* @return array The height and width of the template 'tx' => $_x,
*/ 'ty' => ($this->h-$_y-$_h),
function getTemplateSize($tplidx, $_w=0, $_h=0) { 'lty' => ($this->h-$_y-$_h) - ($this->h-$h) * ($_h/$h)
if (!$this->tpls[$tplidx]) );
return false;
$this->_out(sprintf("q %.4F 0 0 %.4F %.4F %.4F cm", $tData['scaleX'], $tData['scaleY'], $tData['tx']*$this->k, $tData['ty']*$this->k)); // Translate
$tpl =& $this->tpls[$tplidx]; $this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx));
$w = $tpl['w'];
$h = $tpl['h']; $this->lastUsedTemplateData = $tData;
if ($_w == 0 and $_h == 0) { return array("w" => $_w, "h" => $_h);
$_w = $w; }
$_h = $h;
} /**
* Get The calculated Size of a Template
if($_w==0) *
$_w = $_h*$w/$h; * If one size is given, this method calculates the other one.
if($_h==0) *
$_h = $_w*$h/$w; * @param int $tplidx A valid template-Id
* @param int $_w The width of the template
return array("w" => $_w, "h" => $_h); * @param int $_h The height of the template
} * @return array The height and width of the template
*/
/** function getTemplateSize($tplidx, $_w=0, $_h=0) {
* See FPDF-Documentation ;-) if (!$this->tpls[$tplidx])
*/ return false;
function SetFont($family, $style='', $size=0) {
/** $tpl =& $this->tpls[$tplidx];
* force the resetting of font changes in a template $w = $tpl['w'];
*/ $h = $tpl['h'];
if ($this->_intpl)
$this->FontFamily = ''; if ($_w == 0 and $_h == 0) {
$_w = $w;
parent::SetFont($family, $style, $size); $_h = $h;
}
$fontkey = $this->FontFamily.$this->FontStyle;
if($_w==0)
if ($this->_intpl) { $_w = $_h*$w/$h;
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; if($_h==0)
} else { $_h = $_w*$h/$w;
$this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
} return array("w" => $_w, "h" => $_h);
} }
/** /**
* See FPDF/TCPDF-Documentation ;-) * See FPDF/TCPDF-Documentation ;-)
*/ */
function Image($file, $x, $y, $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300) { function SetFont($family, $style='', $size=0, $fontfile='') {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 7) { if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 3) {
$this->Error('More than 7 arguments for the Image method are only available in TCPDF.'); $this->Error('More than 3 arguments for the SetFont method are only available in TCPDF.');
} }
/**
parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi); * force the resetting of font changes in a template
if ($this->_intpl) { */
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; if ($this->_intpl)
} else { $this->FontFamily = '';
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
} parent::SetFont($family, $style, $size, $fontfile);
}
$fontkey = $this->FontFamily.$this->FontStyle;
/**
* See FPDF-Documentation ;-) if ($this->_intpl) {
* $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
* AddPage is not available when you're "in" a template. } else {
*/ $this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
function AddPage($orientation='', $format='') { }
if ($this->_intpl) }
$this->Error('Adding pages in templates isn\'t possible!');
parent::AddPage($orientation, $format); /**
} * 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) {
* Preserve adding Links in Templates ...won't work 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.');
function Link($x, $y, $w, $h, $link) { }
if ($this->_intpl)
$this->Error('Using links in templates aren\'t possible!'); parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden);
parent::Link($x, $y, $w, $h, $link); if ($this->_intpl) {
} $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
} else {
function AddLink() { $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
if ($this->_intpl) }
$this->Error('Adding links in templates aren\'t possible!'); }
return parent::AddLink();
} /**
* See FPDF-Documentation ;-)
function SetLink($link, $y=0, $page=-1) { *
if ($this->_intpl) * AddPage is not available when you're "in" a template.
$this->Error('Setting links in templates aren\'t possible!'); */
parent::SetLink($link, $y, $page); function AddPage($orientation='', $format='') {
} if ($this->_intpl)
$this->Error('Adding pages in templates isn\'t possible!');
/** parent::AddPage($orientation, $format);
* Private Method that writes the form xobjects }
*/
function _putformxobjects() { /**
$filter=($this->compress) ? '/Filter /FlateDecode ' : ''; * Preserve adding Links in Templates ...won't work
reset($this->tpls); */
foreach($this->tpls AS $tplidx => $tpl) { function Link($x, $y, $w, $h, $link, $spaces=0) {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 5) {
$p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer']; $this->Error('More than 5 arguments for the Image method are only available in TCPDF.');
$this->_newobj(); }
$this->tpls[$tplidx]['n'] = $this->n;
$this->_out('<<'.$filter.'/Type /XObject'); if ($this->_intpl)
$this->_out('/Subtype /Form'); $this->Error('Using links in templates aren\'t possible!');
$this->_out('/FormType 1'); parent::Link($x, $y, $w, $h, $link, $spaces);
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',$tpl['x']*$this->k, ($tpl['h']-$tpl['y'])*$this->k, $tpl['w']*$this->k, ($tpl['h']-$tpl['y']-$tpl['h'])*$this->k)); }
$this->_out('/Resources ');
function AddLink() {
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); if ($this->_intpl)
if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) { $this->Error('Adding links in templates aren\'t possible!');
$this->_out('/Font <<'); return parent::AddLink();
foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) }
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
$this->_out('>>'); function SetLink($link, $y=0, $page=-1) {
} if ($this->_intpl)
if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) || $this->Error('Setting links in templates aren\'t possible!');
isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) parent::SetLink($link, $y, $page);
{ }
$this->_out('/XObject <<');
if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { /**
foreach($this->_res['tpl'][$tplidx]['images'] as $image) * Private Method that writes the form xobjects
$this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); */
} function _putformxobjects() {
if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl) reset($this->tpls);
$this->_out($this->tplprefix.$i.' '.$tpl['n'].' 0 R'); foreach($this->tpls AS $tplidx => $tpl) {
}
$this->_out('>>'); $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
} $this->_newobj();
$this->_out('>>'); $this->tpls[$tplidx]['n'] = $this->n;
$this->_out('<<'.$filter.'/Type /XObject');
$this->_out('/Length '.strlen($p).' >>'); $this->_out('/Subtype /Form');
$this->_putstream($p); $this->_out('/FormType 1');
$this->_out('endobj'); $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
} // llx
} $tpl['x']*$this->k,
// lly
/** -$tpl['y']*$this->k,
* Private Method // urx
*/ ($tpl['w']+$tpl['x'])*$this->k,
function _putresources() { // ury
if (!is_subclass_of($this, 'TCPDF')) { ($tpl['h']-$tpl['y'])*$this->k
$this->_putfonts(); ));
$this->_putimages();
$this->_putformxobjects(); if ($tpl['x'] != 0 || $tpl['y'] != 0) {
//Resource dictionary $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',
$this->offsets[2]=strlen($this->buffer); -$tpl['x']*$this->k*2, $tpl['y']*$this->k*2
$this->_out('2 0 obj'); ));
$this->_out('<<'); }
$this->_putresourcedict();
$this->_out('>>'); $this->_out('/Resources ');
$this->_out('endobj');
} else { $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
$this->_putextgstates(); if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
$this->_putocg(); $this->_out('/Font <<');
$this->_putfonts(); foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
$this->_putimages(); $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
$this->_putshaders(); $this->_out('>>');
$this->_putformxobjects(); }
//Resource dictionary if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
$this->offsets[2]=strlen($this->buffer); isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
$this->_out('2 0 obj'); {
$this->_out('<<'); $this->_out('/XObject <<');
$this->_putresourcedict(); if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
$this->_out('>>'); foreach($this->_res['tpl'][$tplidx]['images'] as $image)
$this->_out('endobj'); $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
$this->_putjavascript(); }
$this->_putbookmarks(); if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
// encryption foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl)
if ($this->encrypted) { $this->_out($this->tplprefix.$i.' '.$tpl['n'].' 0 R');
$this->_newobj(); }
$this->enc_obj_id = $this->n; $this->_out('>>');
$this->_out('<<'); }
$this->_putencryption(); $this->_out('>>');
$this->_out('>>');
$this->_out('endobj'); $this->_out('/Length '.strlen($p).' >>');
} $this->_putstream($p);
} $this->_out('endobj');
} }
}
function _putxobjectdict() {
parent::_putxobjectdict(); /**
* Overwritten to add _putformxobjects() after _putimages()
if (count($this->tpls)) { *
foreach($this->tpls as $tplidx => $tpl) { */
$this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R'); function _putimages() {
} parent::_putimages();
} $this->_putformxobjects();
} }
/** function _putxobjectdict() {
* Private Method parent::_putxobjectdict();
*/
function _out($s) { if (count($this->tpls)) {
if ($this->state==2 && $this->_intpl) { foreach($this->tpls as $tplidx => $tpl) {
$this->tpls[$this->tpl]['buffer'] .= $s."\n"; $this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n']));
} else { }
parent::_out($s); }
} }
}
} /**
* Private Method
*/
function _out($s) {
if ($this->state==2 && $this->_intpl) {
$this->tpls[$this->tpl]['buffer'] .= $s."\n";
} else {
parent::_out($s);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.2.1 // FPDI - Version 1.3.2
// //
// Copyright 2004-2008 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.
@ -28,21 +28,12 @@
*/ */
class FPDF extends TCPDF { class FPDF extends TCPDF {
/**
* Missing in TCPDF
*
* @var string
*/
var $padding;
function __get($name) { function __get($name) {
switch ($name) { switch ($name) {
case 'PDFVersion': case 'PDFVersion':
return $this->PDFVersion; return $this->PDFVersion;
case 'k': case 'k':
return $this->k; return $this->k;
case 'lastUsedPageBox':
return $this->lastUsedPageBox;
default: default:
// Error handling // Error handling
$this->Error('Cannot access protected property '.get_class($this).':$'.$name.' / Undefined property: '.get_class($this).'::$'.$name); $this->Error('Cannot access protected property '.get_class($this).':$'.$name.' / Undefined property: '.get_class($this).'::$'.$name);
@ -100,16 +91,62 @@ class FPDF extends TCPDF {
* @return string * @return string
*/ */
function _unescape($s) { function _unescape($s) {
return strtr($s, array( $out = '';
'\\\\' => "\\", for ($count = 0, $n = strlen($s); $count < $n; $count++) {
'\)' => ')', if ($s[$count] != '\\' || $count == $n-1) {
'\(' => '(', $out .= $s[$count];
'\\f' => chr(0x0C), } else {
'\\b' => chr(0x08), switch ($s[++$count]) {
'\\t' => chr(0x09), case ')':
'\\r' => chr(0x0D), case '(':
'\\n' => chr(0x0A), case '\\':
)); $out .= $s[$count];
break;
case 'f':
$out .= chr(0x0C);
break;
case 'b':
$out .= chr(0x08);
break;
case 't':
$out .= chr(0x09);
break;
case 'r':
$out .= chr(0x0D);
break;
case 'n':
$out .= chr(0x0A);
break;
case "\r":
if ($count != $n-1 && $s[$count+1] == "\n")
$count++;
break;
case "\n":
break;
default:
// Octal-Values
if (ord($s[$count]) >= ord('0') &&
ord($s[$count]) <= ord('9')) {
$oct = ''. $s[$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
}
}
$out .= chr(octdec($oct));
} else {
$out .= $s[$count];
}
}
}
}
return $out;
} }
/** /**
@ -119,7 +156,7 @@ class FPDF extends TCPDF {
* @return string * @return string
*/ */
function hex2str($hex) { function hex2str($hex) {
return pack("H*", str_replace(array("\r", "\n", " "), "", $hex)); return pack('H*', str_replace(array("\r", "\n", ' '), '', $hex));
} }
/** /**
@ -129,6 +166,6 @@ class FPDF extends TCPDF {
* @return string * @return string
*/ */
function str2hex($str) { function str2hex($str) {
return current(unpack("H*", $str)); return current(unpack('H*', $str));
} }
} }

View File

@ -1,380 +1,391 @@
<?php <?php
// //
// FPDI - Version 1.2.1 // FPDI - Version 1.3.2
// //
// Copyright 2004-2008 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;
$this->filename = $filename;
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_TOKEN) { $filters[] = $_filter;
$filters[] = $_filter; } else if ($_filter[0] == PDF_TYPE_ARRAY) {
} else if ($_filter[0] == PDF_TYPE_ARRAY) { $filters = $_filter[1];
$filters = $_filter[1]; }
} }
}
$stream = $obj[2][1];
$stream = $obj[2][1];
foreach ($filters AS $_filter) {
foreach ($filters AS $_filter) { switch ($_filter[1]) {
switch ($_filter[1]) { case '/FlateDecode':
case "/FlateDecode": if (function_exists('gzuncompress')) {
if (function_exists('gzuncompress')) { $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : '';
$stream = (strlen($stream) > 0) ? @gzuncompress($stream) : ''; } else {
} else { $this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1]));
$this->fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.",$_filter[1])); }
} if ($stream === false) {
if ($stream === false) { $this->error('Error while decompressing stream.');
$this->fpdi->error("Error while decompressing stream."); }
} break;
break; case '/LZWDecode':
case null: include_once('filters/FilterLZW_FPDI.php');
$stream = $stream; $decoder = new FilterLZW_FPDI($this->fpdi);
break; $stream = $decoder->decode($stream);
default: break;
if (preg_match("/^\/[a-z85]*$/i", $_filter[1], $filterName) && @include_once('decoders'.$_filter[1].'.php')) { case '/ASCII85Decode':
$filterName = substr($_filter[1],1); include_once('filters/FilterASCII85_FPDI.php');
if (class_exists($filterName)) { $decoder = new FilterASCII85_FPDI($this->fpdi);
$decoder = new $filterName($this->fpdi); $stream = $decoder->decode($stream);
$stream = $decoder->decode(trim($stream)); break;
} else { case null:
$this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1])); $stream = $stream;
} break;
} else { default:
$this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1])); $this->error(sprintf('Unsupported Filter: %s',$_filter[1]));
} }
} }
}
return $stream;
return $stream; }
}
/**
/** * Get a Box from a page
* Get a Box from a page * Arrayformat is same as used by fpdf_tpl
* Arrayformat is same as used by fpdf_tpl *
* * @param array $page a /Page
* @param array $page a /Page * @param string $box_index Type of Box @see $availableBoxes
* @param string $box_index Type of Box @see $availableBoxes * @return array
* @return array */
*/ function getPageBox($page, $box_index) {
function getPageBox($page, $box_index) { $page = $this->pdf_resolve_object($this->c,$page);
$page = $this->pdf_resolve_object($this->c,$page); $box = null;
$box = null; if (isset($page[1][1][$box_index]))
if (isset($page[1][1][$box_index])) $box =& $page[1][1][$box_index];
$box =& $page[1][1][$box_index];
if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) {
if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) { $tmp_box = $this->pdf_resolve_object($this->c,$box);
$tmp_box = $this->pdf_resolve_object($this->c,$box); $box = $tmp_box[1];
$box = $tmp_box[1]; }
}
if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) {
if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) { $b =& $box[1];
$b =& $box[1]; return array('x' => $b[0][1]/$this->fpdi->k,
return array("x" => $b[0][1]/$this->fpdi->k, 'y' => $b[1][1]/$this->fpdi->k,
"y" => $b[1][1]/$this->fpdi->k, 'w' => abs($b[0][1]-$b[2][1])/$this->fpdi->k,
"w" => abs($b[0][1]-$b[2][1])/$this->fpdi->k, 'h' => abs($b[1][1]-$b[3][1])/$this->fpdi->k,
"h" => abs($b[1][1]-$b[3][1])/$this->fpdi->k); 'llx' => min($b[0][1], $b[2][1])/$this->fpdi->k,
} else if (!isset ($page[1][1]['/Parent'])) { 'lly' => min($b[1][1], $b[3][1])/$this->fpdi->k,
return false; 'urx' => max($b[0][1], $b[2][1])/$this->fpdi->k,
} else { 'ury' => max($b[1][1], $b[3][1])/$this->fpdi->k,
return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index); );
} } else if (!isset ($page[1][1]['/Parent'])) {
} return false;
} else {
function getPageBoxes($pageno) { return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index);
return $this->_getPageBoxes($this->pages[$pageno-1]); }
} }
/** function getPageBoxes($pageno) {
* Get all Boxes from /Page return $this->_getPageBoxes($this->pages[$pageno-1]);
* }
* @param array a /Page
* @return array /**
*/ * Get all Boxes from /Page
function _getPageBoxes($page) { *
$boxes = array(); * @param array a /Page
* @return array
foreach($this->availableBoxes AS $box) { */
if ($_box = $this->getPageBox($page,$box)) { function _getPageBoxes($page) {
$boxes[$box] = $_box; $boxes = array();
}
} foreach($this->availableBoxes AS $box) {
if ($_box = $this->getPageBox($page,$box)) {
return $boxes; $boxes[$box] = $_box;
} }
}
/**
* Get the page rotation by pageno return $boxes;
* }
* @param integer $pageno
* @return array /**
*/ * Get the page rotation by pageno
function getPageRotation($pageno) { *
return $this->_getPageRotation($this->pages[$pageno-1]); * @param integer $pageno
} * @return array
*/
function _getPageRotation ($obj) { // $obj = /Page function getPageRotation($pageno) {
$obj = $this->pdf_resolve_object($this->c, $obj); return $this->_getPageRotation($this->pages[$pageno-1]);
if (isset ($obj[1][1]['/Rotate'])) { }
$res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']);
if ($res[0] == PDF_TYPE_OBJECT) function _getPageRotation ($obj) { // $obj = /Page
return $res[1]; $obj = $this->pdf_resolve_object($this->c, $obj);
return $res; if (isset ($obj[1][1]['/Rotate'])) {
} else { $res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']);
if (!isset ($obj[1][1]['/Parent'])) { if ($res[0] == PDF_TYPE_OBJECT)
return false; return $res[1];
} else { return $res;
$res = $this->_getPageRotation($obj[1][1]['/Parent']); } else {
if ($res[0] == PDF_TYPE_OBJECT) if (!isset ($obj[1][1]['/Parent'])) {
return $res[1]; return false;
return $res; } else {
} $res = $this->_getPageRotation($obj[1][1]['/Parent']);
} if ($res[0] == PDF_TYPE_OBJECT)
} return $res[1];
return $res;
/** }
* Read all /Page(es) }
* }
* @param object pdf_context
* @param array /Pages /**
* @param array the result-array * Read all /Page(es)
*/ *
function read_pages (&$c, &$pages, &$result) { * @param object pdf_context
// Get the kids dictionary * @param array /Pages
$kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); * @param array the result-array
*/
if (!is_array($kids)) function read_pages (&$c, &$pages, &$result) {
$this->fpdi->Error("Cannot find /Kids in current /Page-Dictionary"); // Get the kids dictionary
foreach ($kids[1] as $v) { $_kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']);
$pg = $this->pdf_resolve_object ($c, $v);
if ($pg[1][1]['/Type'][1] === '/Pages') { if (!is_array($_kids))
// If one of the kids is an embedded $this->error('Cannot find /Kids in current /Page-Dictionary');
// /Pages array, resolve it as well.
$this->read_pages ($c, $pg, $result); if ($_kids[1][0] == PDF_TYPE_ARRAY) {
} else { $kids = $_kids[1][1];
$result[] = $pg; } else {
} $kids = $_kids[1];
} }
}
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
* Get PDF-Version // /Pages array, resolve it as well.
* $this->read_pages ($c, $pg, $result);
* And reset the PDF Version used in FPDI if needed } else {
*/ $result[] = $pg;
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

@ -1,269 +1,319 @@
<?php <?php
/**************************************************************************** /****************************************************************************
* Software: FPDI_Protection * * Software: FPDI_Protection *
* Version: 1.0.2 * * Version: 1.0.3 *
* Date: 2006/11/20 * * Date: 2009/03/06 *
* Author: Klemen VODOPIVEC, Jan Slabon * * Author: Klemen VODOPIVEC, Jan Slabon *
* License: Freeware * * License: Freeware *
* * * *
* You may use and modify this software as you wish as stated in original * * You may use and modify this software as you wish as stated in original *
* FPDF package. * * FPDF package. *
* * * *
* Infos (by Jan Slabon): * * Infos (by Jan Slabon): *
* This class extends the FPDI-class available at http://www.setasign.de * * This class extends the FPDI-class available at http://www.setasign.de *
* so that you can import pages and create new protected pdf files. * * so that you can import pages and create new protected pdf files. *
* * * *
* This release is dedicated to my son Fin Frederik (*2005/06/04) * * This release is dedicated to my son Fin Frederik (*2005/06/04) *
* * * *
****************************************************************************/ ****************************************************************************/
require_once("fpdi.php"); require_once('fpdi.php');
class FPDI_Protection extends FPDI { class FPDI_Protection extends FPDI {
var $encrypted; //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
var $Pvalue; //P entry in pdf document var $Pvalue; //P entry in pdf document
var $enc_obj_id; //encryption object id var $enc_obj_id; //encryption object id
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 = ''; 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";
function FPDI_Protection($orientation='P',$unit='mm',$format='A4') // DOL_CHANGE
{ /*
parent::FPDI($orientation,$unit,$format); function FPDI_Protection($orientation='P',$unit='mm',$format='A4')
$this->_current_obj_id =& $this->current_obj_id; // for FPDI 1.1 compatibility {
parent::FPDI($orientation,$unit,$format);
$this->encrypted=false; $this->_current_obj_id =& $this->current_obj_id; // for FPDI 1.1 compatibility
$this->last_rc4_key = '';
$this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08". $this->encrypted=false;
"\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; $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 */
*
* - permissions is an array with values taken from the following list: /**
* 40bit: copy, print, modify, annot-forms * Function to set permissions as well as user and owner passwords
* 128bit: fill-in, screenreaders, assemble, degraded-print *
* If a value is present it means that the permission is granted * - permissions is an array with values taken from the following list:
* - If a user password is set, user will be prompted before document is opened * 40bit: copy, print, modify, annot-forms
* - If an owner password is set, document can be opened in privilege mode with no * 128bit: fill-in, screenreaders, assemble, degraded-print
* restriction if that password is entered * If a value is present it means that the permission is granted
*/ * - If a user password is set, user will be prompted before document is opened
function SetProtection($permissions=array(),$user_pass='',$owner_pass=null) * - If an owner password is set, document can be opened in privilege mode with no
{ * restriction if that password is entered
$options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 ); */
$protection = 192; function SetProtection($permissions=array(), $user_pass='', $owner_pass=null) {
foreach($permissions as $permission){ $options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 );
if (!isset($options[$permission])) $protection = 192;
$this->Error('Incorrect permission: '.$permission); foreach($permissions as $permission){
$protection += $options[$permission]; if (!isset($options[$permission]))
} $this->Error('Incorrect permission: '.$permission);
if ($owner_pass === null) $protection += $options[$permission];
$owner_pass = uniqid(mt_rand()); }
$this->encrypted = true; if ($owner_pass === null)
$this->_generateencryptionkey($user_pass, $owner_pass, $protection); $owner_pass = uniqid(rand());
} $this->encrypted = true;
$this->_generateencryptionkey($user_pass, $owner_pass, $protection);
}
function _putstream($s)
{
if ($this->encrypted) { function _putstream($s) {
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); if ($this->encrypted) {
} $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
parent::_putstream($s); }
} parent::_putstream($s);
}
function _textstring($s)
{ function _textstring($s) {
if ($this->encrypted) { if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
} }
return parent::_textstring($s); return parent::_textstring($s);
} }
/** /**
* Compute key depending on object number where the encrypted data is stored * Compute key depending on object number where the encrypted data is stored
*/ */
function _objectkey($n) function _objectkey($n) {
{ return substr($this->_md5_16($this->encryption_key.pack('VXxx', $n)), 0, 10);
return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,10); }
}
/**
/** * Escape special characters
* Escape special characters */
*/ function _escape($s) {
function _escape($s) return str_replace(
{ array('\\',')','(',"\r", "\n", "\t"),
return str_replace( array('\\\\','\\)','\\(','\\r', '\\n', '\\t'),$s);
array('\\',')','(',"\r"), }
array('\\\\','\\)','\\(','\\r'),$s);
} function _putresources() {
parent::_putresources();
function _putresources() if ($this->encrypted) {
{ $this->_newobj();
parent::_putresources(); $this->enc_obj_id = $this->_current_obj_id;
if ($this->encrypted) { $this->_out('<<');
$this->_newobj(); $this->_putencryption();
$this->enc_obj_id = $this->_current_obj_id; $this->_out('>>');
$this->_out('<<'); }
$this->_putencryption(); }
$this->_out('>>');
} function _putencryption() {
} $this->_out('/Filter /Standard');
$this->_out('/V 1');
function _putencryption() $this->_out('/R 2');
{ $this->_out('/O ('.$this->_escape($this->Ovalue).')');
$this->_out('/Filter /Standard'); $this->_out('/U ('.$this->_escape($this->Uvalue).')');
$this->_out('/V 1'); $this->_out('/P '.$this->Pvalue);
$this->_out('/R 2'); }
$this->_out('/O ('.$this->_escape($this->Ovalue).')');
$this->_out('/U ('.$this->_escape($this->Uvalue).')');
$this->_out('/P '.$this->Pvalue); function _puttrailer() {
} parent::_puttrailer();
if ($this->encrypted) {
$this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
function _puttrailer() $this->_out('/ID [()()]');
{ }
parent::_puttrailer(); }
if ($this->encrypted) {
$this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
$id = isset($this->fileidentifier) ? $this->fileidentifier : ''; /**
$this->_out('/ID [<'.$id.'><'.$id.'>]'); * RC4 is the standard encryption algorithm used in PDF format
} */
} function _RC4($key, $text) {
if ($this->last_rc4_key != $key) {
$k = str_repeat($key, 256/strlen($key)+1);
/** $rc4 = range(0,255);
* RC4 is the standard encryption algorithm used in PDF format $j = 0;
*/ for ($i=0; $i<256; $i++){
function _RC4($key, $text) $t = $rc4[$i];
{ $j = ($j + $t + ord($k{$i})) % 256;
if ($this->last_rc4_key != $key) { $rc4[$i] = $rc4[$j];
$k = str_repeat($key, 256/strlen($key)+1); $rc4[$j] = $t;
$rc4 = range(0,255); }
$j = 0; $this->last_rc4_key = $key;
for ($i=0; $i<256; $i++){ $this->last_rc4_key_c = $rc4;
$t = $rc4[$i]; } else {
$j = ($j + $t + ord($k{$i})) % 256; $rc4 = $this->last_rc4_key_c;
$rc4[$i] = $rc4[$j]; }
$rc4[$j] = $t;
} $len = strlen($text);
$this->last_rc4_key = $key; $a = 0;
$this->last_rc4_key_c = $rc4; $b = 0;
} else { $out = '';
$rc4 = $this->last_rc4_key_c; for ($i=0; $i<$len; $i++){
} $a = ($a+1)%256;
$t= $rc4[$a];
$len = strlen($text); $b = ($b+$t)%256;
$a = 0; $rc4[$a] = $rc4[$b];
$b = 0; $rc4[$b] = $t;
$out = ''; $k = $rc4[($rc4[$a]+$rc4[$b])%256];
for ($i=0; $i<$len; $i++){ $out.=chr(ord($text{$i}) ^ $k);
$a = ($a+1)%256; }
$t= $rc4[$a];
$b = ($b+$t)%256; return $out;
$rc4[$a] = $rc4[$b]; }
$rc4[$b] = $t;
$k = $rc4[($rc4[$a]+$rc4[$b])%256];
$out.=chr(ord($text{$i}) ^ $k); /**
} * Get MD5 as binary string
*/
return $out; function _md5_16($string) {
} return pack('H*',md5($string));
}
/** /**
* Get MD5 as binary string * Compute O value
*/ */
function _md5_16($string) function _Ovalue($user_pass, $owner_pass) {
{ $tmp = $this->_md5_16($owner_pass);
return pack('H*',md5($string)); $owner_RC4_key = substr($tmp,0,5);
} return $this->_RC4($owner_RC4_key, $user_pass);
}
/**
* Compute O value
*/ /**
function _Ovalue($user_pass, $owner_pass) * Compute U value
{ */
$tmp = $this->_md5_16($owner_pass); function _Uvalue() {
$owner_RC4_key = substr($tmp,0,5); return $this->_RC4($this->encryption_key, $this->padding);
return $this->_RC4($owner_RC4_key, $user_pass); }
}
/**
/** * Compute encryption key
* Compute U value */
*/ function _generateencryptionkey($user_pass, $owner_pass, $protection) {
function _Uvalue() // Pad passwords
{ $user_pass = substr($user_pass.$this->padding,0,32);
return $this->_RC4($this->encryption_key, $this->padding); $owner_pass = substr($owner_pass.$this->padding,0,32);
} // Compute O value
$this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
// Compute encyption key
/** $tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
* Compute encryption key $this->encryption_key = substr($tmp,0,5);
*/ // Compute U value
function _generateencryptionkey($user_pass, $owner_pass, $protection) $this->Uvalue = $this->_Uvalue();
{ // Compute P value
// Pad passwords $this->Pvalue = -(($protection^255)+1);
$user_pass = substr($user_pass.$this->padding,0,32); }
$owner_pass = substr($owner_pass.$this->padding,0,32);
// Compute O value
$this->Ovalue = $this->_Ovalue($user_pass,$owner_pass); function pdf_write_value(&$value) {
// Compute encyption key switch ($value[0]) {
$tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF"); case PDF_TYPE_STRING :
$this->encryption_key = substr($tmp,0,5); if ($this->encrypted) {
// Compute U value $value[1] = $this->_unescape($value[1]);
$this->Uvalue = $this->_Uvalue(); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
// Compute P value $value[1] = $this->_escape($value[1]);
$this->Pvalue = -(($protection^255)+1); }
} break;
case PDF_TYPE_STREAM :
function pdf_write_value(&$value) { if ($this->encrypted) {
switch ($value[0]) { $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
case PDF_TYPE_STRING : }
if ($this->encrypted) { break;
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
$value[1] = $this->_escape($value[1]); case PDF_TYPE_HEX :
}
break; if ($this->encrypted) {
$value[1] = $this->hex2str($value[1]);
case PDF_TYPE_STREAM : $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
if ($this->encrypted) {
$value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]); // remake hexstring of encrypted string
} $value[1] = $this->str2hex($value[1]);
break; }
break;
case PDF_TYPE_HEX : }
if ($this->encrypted) { parent::pdf_write_value($value);
$value[1] = $this->hex2str($value[1]); }
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
// remake hexstring of encrypted string function hex2str($hex) {
$value[1] = $this->str2hex($value[1]); return pack('H*', str_replace(array("\r","\n",' '),'', $hex));
} }
break;
} function str2hex($str) {
return current(unpack('H*',$str));
parent::pdf_write_value($value); }
}
/**
* Deescape special characters
function hex2str($hex) { */
return pack("H*", str_replace(array("\r","\n"," "),"", $hex)); function _unescape($s) {
} $out = '';
for ($count = 0, $n = strlen($s); $count < $n; $count++) {
function str2hex($str) { if ($s[$count] != '\\' || $count == $n-1) {
return current(unpack("H*",$str)); $out .= $s[$count];
} } else {
} switch ($s[++$count]) {
case ')':
?> case '(':
case '\\':
$out .= $s[$count];
break;
case 'f':
$out .= chr(0x0C);
break;
case 'b':
$out .= chr(0x08);
break;
case 't':
$out .= chr(0x09);
break;
case 'r':
$out .= chr(0x0D);
break;
case 'n':
$out .= chr(0x0A);
break;
case "\r":
if ($count != $n-1 && $s[$count+1] == "\n")
$count++;
break;
case "\n":
break;
default:
// Octal-Values
if (ord($s[$count]) >= ord('0') &&
ord($s[$count]) <= ord('9')) {
$oct = ''. $s[$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
}
}
$out .= chr(octdec($oct));
} else {
$out .= $s[$count];
}
}
}
}
return $out;
}
}

View File

@ -1,82 +1,103 @@
<?php <?php
// //
// FPDI - Version 1.2.1 // FPDI - Version 1.3.2
// //
// Copyright 2004-2008 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.
// //
class pdf_context { $__tmp = version_compare(phpversion(), "5") == -1 ? array('pdf_context') : array('pdf_context', false);
if (!call_user_func_array('class_exists', $__tmp)) {
var $file;
var $buffer; class pdf_context {
var $offset;
var $length; /**
* Modi
var $stack; *
* @var integer 0 = file | 1 = string
// Constructor */
var $_mode = 0;
function pdf_context($f) {
$this->file = $f; var $file;
$this->reset(); var $buffer;
} var $offset;
var $length;
// Optionally move the file
// pointer to a new location var $stack;
// and reset the buffered data
// Constructor
function reset($pos = null, $l = 100) {
if (!is_null ($pos)) { function pdf_context(&$f) {
fseek ($this->file, $pos); $this->file =& $f;
} if (is_string($this->file))
$this->_mode = 1;
$this->buffer = $l > 0 ? fread($this->file, $l) : ''; $this->reset();
$this->length = strlen($this->buffer); }
if ($this->length < $l)
$this->increase_length($l - $this->length); // Optionally move the file
$this->offset = 0; // pointer to a new location
$this->stack = array(); // and reset the buffered data
}
function reset($pos = null, $l = 100) {
// Make sure that there is at least one if ($this->_mode == 0) {
// character beyond the current offset in if (!is_null ($pos)) {
// the buffer to prevent the tokenizer fseek ($this->file, $pos);
// from attempting to access data that does }
// not exist
$this->buffer = $l > 0 ? fread($this->file, $l) : '';
function ensure_content() { $this->length = strlen($this->buffer);
if ($this->offset >= $this->length - 1) { if ($this->length < $l)
return $this->increase_length(); $this->increase_length($l - $this->length);
} else { } else {
return true; $this->buffer = $this->file;
} $this->length = strlen($this->buffer);
} }
$this->offset = 0;
// Forcefully read more data into the buffer $this->stack = array();
}
function increase_length($l=100) {
if (feof($this->file)) { // Make sure that there is at least one
return false; // character beyond the current offset in
} else { // the buffer to prevent the tokenizer
$totalLength = $this->length + $l; // from attempting to access data that does
do { // not exist
$this->buffer .= fread($this->file, $totalLength-$this->length);
} while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); function ensure_content() {
if ($this->offset >= $this->length - 1) {
return true; return $this->increase_length();
} } else {
} return true;
}
} }
// Forcefully read more data into the buffer
function increase_length($l=100) {
if ($this->_mode == 0 && feof($this->file)) {
return false;
} else if ($this->_mode == 0) {
$totalLength = $this->length + $l;
do {
$this->buffer .= fread($this->file, $totalLength-$this->length);
} while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
return true;
} else {
return false;
}
}
}
}
unset($__tmp);

File diff suppressed because it is too large Load Diff