Work on FPDF replacement by TCPDF
This commit is contained in:
parent
73d451640a
commit
11479ecbe6
@ -8,16 +8,6 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/* Begin DOLCHANGE Added by Regis */
|
|
||||||
// height of cell repect font height
|
|
||||||
define("K_CELL_HEIGHT_RATIO", 1.25);
|
|
||||||
// Repertoire des documents de fckeditor
|
|
||||||
if (! empty($conf->fckeditor->dir_output)) define ("K_PATH_CACHE", $conf->fckeditor->dir_output);
|
|
||||||
// url qui sera substituer par le K_PATH_CACHE lorsqu'une image sera integree au pdf
|
|
||||||
if (defined('DOL_URL_ROOT')) define ("K_PATH_URL_CACHE", DOL_URL_ROOT."/document.php?modulepart=editor&file=");
|
|
||||||
/* End DOLCHANGE Added by Regis */
|
|
||||||
|
|
||||||
|
|
||||||
define('FPDF_VERSION','1.6');
|
define('FPDF_VERSION','1.6');
|
||||||
|
|
||||||
class FPDF
|
class FPDF
|
||||||
|
|||||||
@ -1,412 +1,409 @@
|
|||||||
<?php
|
<?php
|
||||||
//
|
//
|
||||||
// FPDF_TPL - Version 1.1.4
|
// FPDF_TPL - Version 1.1.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.
|
||||||
//
|
//
|
||||||
|
|
||||||
// DOLCHANGE
|
class FPDF_TPL extends FPDF {
|
||||||
require_once(FPDF_PATH."fpdf.php");
|
/**
|
||||||
|
* Array of Tpl-Data
|
||||||
class FPDF_TPL extends FPDF {
|
* @var array
|
||||||
/**
|
*/
|
||||||
* Array of Tpl-Data
|
var $tpls = array();
|
||||||
* @var array
|
|
||||||
*/
|
/**
|
||||||
var $tpls = array();
|
* Current Template-ID
|
||||||
|
* @var int
|
||||||
/**
|
*/
|
||||||
* Current Template-ID
|
var $tpl = 0;
|
||||||
* @var int
|
|
||||||
*/
|
/**
|
||||||
var $tpl = 0;
|
* "In Template"-Flag
|
||||||
|
* @var boolean
|
||||||
/**
|
*/
|
||||||
* "In Template"-Flag
|
var $_intpl = false;
|
||||||
* @var boolean
|
|
||||||
*/
|
/**
|
||||||
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 $tplprefix = "/TPL";
|
||||||
* @var string A String defining the Prefix used as Template-Object-Names. Have to beginn with an /
|
|
||||||
*/
|
/**
|
||||||
var $tplprefix = "/TPL";
|
* Resources used By Templates and Pages
|
||||||
|
* @var array
|
||||||
/**
|
*/
|
||||||
* Resources used By Templates and Pages
|
var $_res = array();
|
||||||
* @var array
|
|
||||||
*/
|
/**
|
||||||
var $_res = array();
|
* Last used Template data
|
||||||
|
*
|
||||||
/**
|
* @var array
|
||||||
* Last used Template data
|
*/
|
||||||
*
|
var $lastUsedTemplateData = array();
|
||||||
* @var array
|
|
||||||
*/
|
/**
|
||||||
var $lastUsedTemplateData = array();
|
* Start a Template
|
||||||
|
*
|
||||||
/**
|
* This method starts a template. You can give own coordinates to build an own sized
|
||||||
* Start a Template
|
* 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,
|
||||||
* This method starts a template. You can give own coordinates to build an own sized
|
* you have to set the Margins and "Cursor"-Position manual after beginTemplate-Call.
|
||||||
* 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,
|
* If no parameter is given, the template uses the current page-size.
|
||||||
* you have to set the Margins and "Cursor"-Position manual after beginTemplate-Call.
|
* The Method returns an ID of the current Template. This ID is used later for using this template.
|
||||||
*
|
* Warning: A created Template is used in PDF at all events. Still if you don't use it after creation!
|
||||||
* If no parameter is given, the template uses the current page-size.
|
*
|
||||||
* The Method returns an ID of the current Template. This ID is used later for using this template.
|
* @param int $x The x-coordinate given in user-unit
|
||||||
* Warning: A created Template is used in PDF at all events. Still if you don't use it after creation!
|
* @param int $y The y-coordinate given in user-unit
|
||||||
*
|
* @param int $w The width given in user-unit
|
||||||
* @param int $x The x-coordinate given in user-unit
|
* @param int $h The height given in user-unit
|
||||||
* @param int $y The y-coordinate given in user-unit
|
* @return int The ID of new created Template
|
||||||
* @param int $w The width given in user-unit
|
*/
|
||||||
* @param int $h The height given in user-unit
|
function beginTemplate($x=null, $y=null, $w=null, $h=null) {
|
||||||
* @return int The ID of new created Template
|
if ($this->page <= 0)
|
||||||
*/
|
$this->error("You have to add a page to fpdf first!");
|
||||||
function beginTemplate($x=null, $y=null, $w=null, $h=null) {
|
|
||||||
if ($this->page <= 0)
|
if ($x == null)
|
||||||
$this->error("You have to add a page to fpdf first!");
|
$x = 0;
|
||||||
|
if ($y == null)
|
||||||
if ($x == null)
|
$y = 0;
|
||||||
$x = 0;
|
if ($w == null)
|
||||||
if ($y == null)
|
$w = $this->w;
|
||||||
$y = 0;
|
if ($h == null)
|
||||||
if ($w == null)
|
$h = $this->h;
|
||||||
$w = $this->w;
|
|
||||||
if ($h == null)
|
// Save settings
|
||||||
$h = $this->h;
|
$this->tpl++;
|
||||||
|
$tpl =& $this->tpls[$this->tpl];
|
||||||
// Save settings
|
$tpl = array(
|
||||||
$this->tpl++;
|
'o_x' => $this->x,
|
||||||
$tpl =& $this->tpls[$this->tpl];
|
'o_y' => $this->y,
|
||||||
$tpl = array(
|
'o_AutoPageBreak' => $this->AutoPageBreak,
|
||||||
'o_x' => $this->x,
|
'o_bMargin' => $this->bMargin,
|
||||||
'o_y' => $this->y,
|
'o_tMargin' => $this->tMargin,
|
||||||
'o_AutoPageBreak' => $this->AutoPageBreak,
|
'o_lMargin' => $this->lMargin,
|
||||||
'o_bMargin' => $this->bMargin,
|
'o_rMargin' => $this->rMargin,
|
||||||
'o_tMargin' => $this->tMargin,
|
'o_h' => $this->h,
|
||||||
'o_lMargin' => $this->lMargin,
|
'o_w' => $this->w,
|
||||||
'o_rMargin' => $this->rMargin,
|
'buffer' => '',
|
||||||
'o_h' => $this->h,
|
'x' => $x,
|
||||||
'o_w' => $this->w,
|
'y' => $y,
|
||||||
'buffer' => '',
|
'w' => $w,
|
||||||
'x' => $x,
|
'h' => $h
|
||||||
'y' => $y,
|
);
|
||||||
'w' => $w,
|
|
||||||
'h' => $h
|
$this->SetAutoPageBreak(false);
|
||||||
);
|
|
||||||
|
// Define own high and width to calculate possitions correct
|
||||||
$this->SetAutoPageBreak(false);
|
$this->h = $h;
|
||||||
|
$this->w = $w;
|
||||||
// Define own high and width to calculate possitions correct
|
|
||||||
$this->h = $h;
|
$this->_intpl = true;
|
||||||
$this->w = $w;
|
$this->SetXY($x+$this->lMargin, $y+$this->tMargin);
|
||||||
|
$this->SetRightMargin($this->w-$w+$this->rMargin);
|
||||||
$this->_intpl = true;
|
|
||||||
$this->SetXY($x+$this->lMargin, $y+$this->tMargin);
|
return $this->tpl;
|
||||||
$this->SetRightMargin($this->w-$w+$this->rMargin);
|
}
|
||||||
|
|
||||||
return $this->tpl;
|
/**
|
||||||
}
|
* End Template
|
||||||
|
*
|
||||||
/**
|
* This method ends a template and reset initiated variables on beginTemplate.
|
||||||
* End Template
|
*
|
||||||
*
|
* @return mixed If a template is opened, the ID is returned. If not a false is returned.
|
||||||
* This method ends a template and reset initiated variables on beginTemplate.
|
*/
|
||||||
*
|
function endTemplate() {
|
||||||
* @return mixed If a template is opened, the ID is returned. If not a false is returned.
|
if ($this->_intpl) {
|
||||||
*/
|
$this->_intpl = false;
|
||||||
function endTemplate() {
|
$tpl =& $this->tpls[$this->tpl];
|
||||||
if ($this->_intpl) {
|
$this->SetXY($tpl['o_x'], $tpl['o_y']);
|
||||||
$this->_intpl = false;
|
$this->tMargin = $tpl['o_tMargin'];
|
||||||
$tpl =& $this->tpls[$this->tpl];
|
$this->lMargin = $tpl['o_lMargin'];
|
||||||
$this->SetXY($tpl['o_x'], $tpl['o_y']);
|
$this->rMargin = $tpl['o_rMargin'];
|
||||||
$this->tMargin = $tpl['o_tMargin'];
|
$this->h = $tpl['o_h'];
|
||||||
$this->lMargin = $tpl['o_lMargin'];
|
$this->w = $tpl['o_w'];
|
||||||
$this->rMargin = $tpl['o_rMargin'];
|
$this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']);
|
||||||
$this->h = $tpl['o_h'];
|
|
||||||
$this->w = $tpl['o_w'];
|
return $this->tpl;
|
||||||
$this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']);
|
} else {
|
||||||
|
return false;
|
||||||
return $this->tpl;
|
}
|
||||||
} else {
|
}
|
||||||
return false;
|
|
||||||
}
|
/**
|
||||||
}
|
* Use a Template in current Page or other Template
|
||||||
|
*
|
||||||
/**
|
* You can use a template in a page or in another template.
|
||||||
* Use a Template in current Page or other 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
|
||||||
* You can use a template in a page or in another template.
|
* if one is given. If no parameter is given the origin size as defined in
|
||||||
* You can give the used template a new size like you use the Image()-method.
|
* beginTemplate() is used.
|
||||||
* All parameters are optional. The width or height is calculated automaticaly
|
* The calculated or used width and height are returned as an array.
|
||||||
* if one is given. If no parameter is given the origin size as defined in
|
*
|
||||||
* beginTemplate() is used.
|
* @param int $tplidx A valid template-Id
|
||||||
* The calculated or used width and height are returned as an array.
|
* @param int $_x The x-position
|
||||||
*
|
* @param int $_y The y-position
|
||||||
* @param int $tplidx A valid template-Id
|
* @param int $_w The new width of the template
|
||||||
* @param int $_x The x-position
|
* @param int $_h The new height of the template
|
||||||
* @param int $_y The y-position
|
* @retrun array The height and width of the template
|
||||||
* @param int $_w The new width of the template
|
*/
|
||||||
* @param int $_h The new height of the template
|
function useTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
|
||||||
* @retrun array The height and width of the template
|
if ($this->page <= 0)
|
||||||
*/
|
$this->error("You have to add a page to fpdf first!");
|
||||||
function useTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
|
|
||||||
if ($this->page <= 0)
|
if (!isset($this->tpls[$tplidx]))
|
||||||
$this->error("You have to add a page to fpdf first!");
|
$this->error("Template does not exist!");
|
||||||
|
|
||||||
if (!isset($this->tpls[$tplidx]))
|
if ($this->_intpl) {
|
||||||
$this->error("Template does not exist!");
|
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
|
||||||
|
}
|
||||||
if ($this->_intpl) {
|
|
||||||
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
|
$tpl =& $this->tpls[$tplidx];
|
||||||
}
|
$w = $tpl['w'];
|
||||||
|
$h = $tpl['h'];
|
||||||
$tpl =& $this->tpls[$tplidx];
|
|
||||||
$w = $tpl['w'];
|
if ($_x == null)
|
||||||
$h = $tpl['h'];
|
$_x = 0;
|
||||||
|
if ($_y == null)
|
||||||
if ($_x == null)
|
$_y = 0;
|
||||||
$_x = 0;
|
|
||||||
if ($_y == null)
|
$_x += $tpl['x'];
|
||||||
$_y = 0;
|
$_y += $tpl['y'];
|
||||||
|
|
||||||
$_x += $tpl['x'];
|
$wh = $this->getTemplateSize($tplidx, $_w, $_h);
|
||||||
$_y += $tpl['y'];
|
$_w = $wh['w'];
|
||||||
|
$_h = $wh['h'];
|
||||||
$wh = $this->getTemplateSize($tplidx, $_w, $_h);
|
|
||||||
$_w = $wh['w'];
|
$tData = array(
|
||||||
$_h = $wh['h'];
|
'x' => $this->x,
|
||||||
|
'y' => $this->y,
|
||||||
$tData = array(
|
'w' => $_w,
|
||||||
'x' => $this->x,
|
'h' => $_h,
|
||||||
'y' => $this->y,
|
'scaleX' => ($_w/$w),
|
||||||
'w' => $_w,
|
'scaleY' => ($_h/$h),
|
||||||
'h' => $_h,
|
'tx' => $_x,
|
||||||
'scaleX' => ($_w/$w),
|
'ty' => ($this->h-$_y-$_h),
|
||||||
'scaleY' => ($_h/$h),
|
'lty' => ($this->h-$_y-$_h) - ($this->h-$h) * ($_h/$h)
|
||||||
'tx' => $_x,
|
);
|
||||||
'ty' => ($this->h-$_y-$_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('%s%d Do Q', $this->tplprefix, $tplidx));
|
||||||
|
|
||||||
$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->lastUsedTemplateData = $tData;
|
||||||
$this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx));
|
|
||||||
|
return array("w" => $_w, "h" => $_h);
|
||||||
$this->lastUsedTemplateData = $tData;
|
}
|
||||||
|
|
||||||
return array("w" => $_w, "h" => $_h);
|
/**
|
||||||
}
|
* Get The calculated Size of a Template
|
||||||
|
*
|
||||||
/**
|
* If one size is given, this method calculates the other one.
|
||||||
* Get The calculated Size of a Template
|
*
|
||||||
*
|
* @param int $tplidx A valid template-Id
|
||||||
* If one size is given, this method calculates the other one.
|
* @param int $_w The width of the template
|
||||||
*
|
* @param int $_h The height of the template
|
||||||
* @param int $tplidx A valid template-Id
|
* @return array The height and width of the template
|
||||||
* @param int $_w The width of the template
|
*/
|
||||||
* @param int $_h The height of the template
|
function getTemplateSize($tplidx, $_w=0, $_h=0) {
|
||||||
* @return array The height and width of the template
|
if (!$this->tpls[$tplidx])
|
||||||
*/
|
return false;
|
||||||
function getTemplateSize($tplidx, $_w=0, $_h=0) {
|
|
||||||
if (!$this->tpls[$tplidx])
|
$tpl =& $this->tpls[$tplidx];
|
||||||
return false;
|
$w = $tpl['w'];
|
||||||
|
$h = $tpl['h'];
|
||||||
$tpl =& $this->tpls[$tplidx];
|
|
||||||
$w = $tpl['w'];
|
if ($_w == 0 and $_h == 0) {
|
||||||
$h = $tpl['h'];
|
$_w = $w;
|
||||||
|
$_h = $h;
|
||||||
if ($_w == 0 and $_h == 0) {
|
}
|
||||||
$_w = $w;
|
|
||||||
$_h = $h;
|
if($_w==0)
|
||||||
}
|
$_w = $_h*$w/$h;
|
||||||
|
if($_h==0)
|
||||||
if($_w==0)
|
$_h = $_w*$h/$w;
|
||||||
$_w = $_h*$w/$h;
|
|
||||||
if($_h==0)
|
return array("w" => $_w, "h" => $_h);
|
||||||
$_h = $_w*$h/$w;
|
}
|
||||||
|
|
||||||
return array("w" => $_w, "h" => $_h);
|
/**
|
||||||
}
|
* See FPDF/TCPDF-Documentation ;-)
|
||||||
|
*/
|
||||||
/**
|
function SetFont($family, $style='', $size=0, $fontfile='') {
|
||||||
* See FPDF/TCPDF-Documentation ;-)
|
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 3) {
|
||||||
*/
|
$this->Error('More than 3 arguments for the SetFont method are only available in TCPDF.');
|
||||||
function SetFont($family, $style='', $size=0, $fontfile='') {
|
}
|
||||||
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 3) {
|
/**
|
||||||
$this->Error('More than 3 arguments for the SetFont method are only available in TCPDF.');
|
* force the resetting of font changes in a template
|
||||||
}
|
*/
|
||||||
/**
|
if ($this->_intpl)
|
||||||
* force the resetting of font changes in a template
|
$this->FontFamily = '';
|
||||||
*/
|
|
||||||
if ($this->_intpl)
|
parent::SetFont($family, $style, $size, $fontfile);
|
||||||
$this->FontFamily = '';
|
|
||||||
|
$fontkey = $this->FontFamily.$this->FontStyle;
|
||||||
parent::SetFont($family, $style, $size, $fontfile);
|
|
||||||
|
if ($this->_intpl) {
|
||||||
$fontkey = $this->FontFamily.$this->FontStyle;
|
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
||||||
|
} else {
|
||||||
if ($this->_intpl) {
|
$this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
||||||
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
}
|
||||||
} else {
|
}
|
||||||
$this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
|
||||||
}
|
/**
|
||||||
}
|
* 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) {
|
||||||
* See FPDF/TCPDF-Documentation ;-)
|
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 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) {
|
}
|
||||||
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.');
|
parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden);
|
||||||
}
|
if ($this->_intpl) {
|
||||||
|
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
|
||||||
parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden);
|
} else {
|
||||||
if ($this->_intpl) {
|
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
|
||||||
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
|
}
|
||||||
} else {
|
}
|
||||||
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
|
|
||||||
}
|
/**
|
||||||
}
|
* See FPDF-Documentation ;-)
|
||||||
|
*
|
||||||
/**
|
* AddPage is not available when you're "in" a template.
|
||||||
* See FPDF-Documentation ;-)
|
*/
|
||||||
*
|
function AddPage($orientation='', $format='') {
|
||||||
* AddPage is not available when you're "in" a template.
|
if ($this->_intpl)
|
||||||
*/
|
$this->Error('Adding pages in templates isn\'t possible!');
|
||||||
function AddPage($orientation='', $format='') {
|
parent::AddPage($orientation, $format);
|
||||||
if ($this->_intpl)
|
}
|
||||||
$this->Error('Adding pages in templates isn\'t possible!');
|
|
||||||
parent::AddPage($orientation, $format);
|
/**
|
||||||
}
|
* Preserve adding Links in Templates ...won't work
|
||||||
|
*/
|
||||||
/**
|
function Link($x, $y, $w, $h, $link, $spaces=0) {
|
||||||
* Preserve adding Links in Templates ...won't work
|
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.');
|
||||||
function Link($x, $y, $w, $h, $link, $spaces=0) {
|
}
|
||||||
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.');
|
if ($this->_intpl)
|
||||||
}
|
$this->Error('Using links in templates aren\'t possible!');
|
||||||
|
parent::Link($x, $y, $w, $h, $link, $spaces);
|
||||||
if ($this->_intpl)
|
}
|
||||||
$this->Error('Using links in templates aren\'t possible!');
|
|
||||||
parent::Link($x, $y, $w, $h, $link, $spaces);
|
function AddLink() {
|
||||||
}
|
if ($this->_intpl)
|
||||||
|
$this->Error('Adding links in templates aren\'t possible!');
|
||||||
function AddLink() {
|
return parent::AddLink();
|
||||||
if ($this->_intpl)
|
}
|
||||||
$this->Error('Adding links in templates aren\'t possible!');
|
|
||||||
return parent::AddLink();
|
function SetLink($link, $y=0, $page=-1) {
|
||||||
}
|
if ($this->_intpl)
|
||||||
|
$this->Error('Setting links in templates aren\'t possible!');
|
||||||
function SetLink($link, $y=0, $page=-1) {
|
parent::SetLink($link, $y, $page);
|
||||||
if ($this->_intpl)
|
}
|
||||||
$this->Error('Setting links in templates aren\'t possible!');
|
|
||||||
parent::SetLink($link, $y, $page);
|
/**
|
||||||
}
|
* Private Method that writes the form xobjects
|
||||||
|
*/
|
||||||
/**
|
function _putformxobjects() {
|
||||||
* Private Method that writes the form xobjects
|
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
||||||
*/
|
reset($this->tpls);
|
||||||
function _putformxobjects() {
|
foreach($this->tpls AS $tplidx => $tpl) {
|
||||||
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
|
||||||
reset($this->tpls);
|
$p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
|
||||||
foreach($this->tpls AS $tplidx => $tpl) {
|
$this->_newobj();
|
||||||
|
$this->tpls[$tplidx]['n'] = $this->n;
|
||||||
$p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
|
$this->_out('<<'.$filter.'/Type /XObject');
|
||||||
$this->_newobj();
|
$this->_out('/Subtype /Form');
|
||||||
$this->tpls[$tplidx]['n'] = $this->n;
|
$this->_out('/FormType 1');
|
||||||
$this->_out('<<'.$filter.'/Type /XObject');
|
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
||||||
$this->_out('/Subtype /Form');
|
// llx
|
||||||
$this->_out('/FormType 1');
|
$tpl['x']*$this->k,
|
||||||
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
// lly
|
||||||
// llx
|
-$tpl['y']*$this->k,
|
||||||
$tpl['x']*$this->k,
|
// urx
|
||||||
// lly
|
($tpl['w']+$tpl['x'])*$this->k,
|
||||||
-$tpl['y']*$this->k,
|
// ury
|
||||||
// urx
|
($tpl['h']-$tpl['y'])*$this->k
|
||||||
($tpl['w']+$tpl['x'])*$this->k,
|
));
|
||||||
// ury
|
|
||||||
($tpl['h']-$tpl['y'])*$this->k
|
if ($tpl['x'] != 0 || $tpl['y'] != 0) {
|
||||||
));
|
$this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',
|
||||||
|
-$tpl['x']*$this->k*2, $tpl['y']*$this->k*2
|
||||||
if ($tpl['x'] != 0 || $tpl['y'] != 0) {
|
));
|
||||||
$this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',
|
}
|
||||||
-$tpl['x']*$this->k*2, $tpl['y']*$this->k*2
|
|
||||||
));
|
$this->_out('/Resources ');
|
||||||
}
|
|
||||||
|
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
||||||
$this->_out('/Resources ');
|
if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
|
||||||
|
$this->_out('/Font <<');
|
||||||
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
|
||||||
if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
|
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
|
||||||
$this->_out('/Font <<');
|
$this->_out('>>');
|
||||||
foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
|
}
|
||||||
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
|
if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
|
||||||
$this->_out('>>');
|
isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
|
||||||
}
|
{
|
||||||
if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
|
$this->_out('/XObject <<');
|
||||||
isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
|
if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
|
||||||
{
|
foreach($this->_res['tpl'][$tplidx]['images'] as $image)
|
||||||
$this->_out('/XObject <<');
|
$this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
|
||||||
if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
|
}
|
||||||
foreach($this->_res['tpl'][$tplidx]['images'] as $image)
|
if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
|
||||||
$this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
|
foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl)
|
||||||
}
|
$this->_out($this->tplprefix.$i.' '.$tpl['n'].' 0 R');
|
||||||
if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
|
}
|
||||||
foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl)
|
$this->_out('>>');
|
||||||
$this->_out($this->tplprefix.$i.' '.$tpl['n'].' 0 R');
|
}
|
||||||
}
|
$this->_out('>>');
|
||||||
$this->_out('>>');
|
|
||||||
}
|
$this->_out('/Length '.strlen($p).' >>');
|
||||||
$this->_out('>>');
|
$this->_putstream($p);
|
||||||
|
$this->_out('endobj');
|
||||||
$this->_out('/Length '.strlen($p).' >>');
|
}
|
||||||
$this->_putstream($p);
|
}
|
||||||
$this->_out('endobj');
|
|
||||||
}
|
/**
|
||||||
}
|
* Overwritten to add _putformxobjects() after _putimages()
|
||||||
|
*
|
||||||
/**
|
*/
|
||||||
* Overwritten to add _putformxobjects() after _putimages()
|
function _putimages() {
|
||||||
*
|
parent::_putimages();
|
||||||
*/
|
$this->_putformxobjects();
|
||||||
function _putimages() {
|
}
|
||||||
parent::_putimages();
|
|
||||||
$this->_putformxobjects();
|
function _putxobjectdict() {
|
||||||
}
|
parent::_putxobjectdict();
|
||||||
|
|
||||||
function _putxobjectdict() {
|
if (count($this->tpls)) {
|
||||||
parent::_putxobjectdict();
|
foreach($this->tpls as $tplidx => $tpl) {
|
||||||
|
$this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n']));
|
||||||
if (count($this->tpls)) {
|
}
|
||||||
foreach($this->tpls as $tplidx => $tpl) {
|
}
|
||||||
$this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n']));
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
}
|
* Private Method
|
||||||
|
*/
|
||||||
/**
|
function _out($s) {
|
||||||
* Private Method
|
if ($this->state==2 && $this->_intpl) {
|
||||||
*/
|
$this->tpls[$this->tpl]['buffer'] .= $s."\n";
|
||||||
function _out($s) {
|
} else {
|
||||||
if ($this->state==2 && $this->_intpl) {
|
parent::_out($s);
|
||||||
$this->tpls[$this->tpl]['buffer'] .= $s."\n";
|
}
|
||||||
} else {
|
}
|
||||||
parent::_out($s);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,319 +1,333 @@
|
|||||||
<?php
|
<?php
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Software: FPDI_Protection *
|
* Software: FPDI_Protection *
|
||||||
* Version: 1.0.3 *
|
* Version: 1.0.3 *
|
||||||
* Date: 2009/03/06 *
|
* 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');
|
/* Begin DOLCHANGE Added by Regis */
|
||||||
|
// height of cell repect font height
|
||||||
class FPDI_Protection extends FPDI {
|
define("K_CELL_HEIGHT_RATIO", 1.25);
|
||||||
|
// Repertoire des documents de fckeditor
|
||||||
var $encrypted = false; //whether document is protected
|
if (! empty($conf->fckeditor->dir_output)) define ("K_PATH_CACHE", $conf->fckeditor->dir_output);
|
||||||
var $Uvalue; //U entry in pdf document
|
// url qui sera substituer par le K_PATH_CACHE lorsqu'une image sera integree au pdf
|
||||||
var $Ovalue; //O entry in pdf document
|
if (defined('DOL_URL_ROOT')) define ("K_PATH_URL_CACHE", DOL_URL_ROOT."/document.php?modulepart=editor&file=");
|
||||||
var $Pvalue; //P entry in pdf document
|
/* End DOLCHANGE Added by Regis */
|
||||||
var $enc_obj_id; //encryption object id
|
|
||||||
var $last_rc4_key = ''; //last RC4 key encrypted (cached for optimisation)
|
// DOLCHANGE
|
||||||
var $last_rc4_key_c; //last RC4 computed key
|
require_once(FPDF_PATH."fpdf.php");
|
||||||
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
|
|
||||||
/*
|
require_once('fpdi.php');
|
||||||
function FPDI_Protection($orientation='P',$unit='mm',$format='A4')
|
|
||||||
{
|
class FPDI_Protection extends FPDI {
|
||||||
parent::FPDI($orientation,$unit,$format);
|
|
||||||
$this->_current_obj_id =& $this->current_obj_id; // for FPDI 1.1 compatibility
|
var $encrypted = false; //whether document is protected
|
||||||
|
var $Uvalue; //U entry in pdf document
|
||||||
$this->encrypted=false;
|
var $Ovalue; //O entry in pdf document
|
||||||
$this->last_rc4_key = '';
|
var $Pvalue; //P entry in pdf document
|
||||||
$this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
|
var $enc_obj_id; //encryption object id
|
||||||
"\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
|
var $last_rc4_key = ''; //last RC4 key encrypted (cached for optimisation)
|
||||||
}
|
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";
|
||||||
|
|
||||||
/**
|
// DOL_CHANGE
|
||||||
* Function to set permissions as well as user and owner passwords
|
/*
|
||||||
*
|
function FPDI_Protection($orientation='P',$unit='mm',$format='A4')
|
||||||
* - permissions is an array with values taken from the following list:
|
{
|
||||||
* 40bit: copy, print, modify, annot-forms
|
parent::FPDI($orientation,$unit,$format);
|
||||||
* 128bit: fill-in, screenreaders, assemble, degraded-print
|
$this->_current_obj_id =& $this->current_obj_id; // for FPDI 1.1 compatibility
|
||||||
* 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
|
$this->encrypted=false;
|
||||||
* - If an owner password is set, document can be opened in privilege mode with no
|
$this->last_rc4_key = '';
|
||||||
* restriction if that password is entered
|
$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 SetProtection($permissions=array(), $user_pass='', $owner_pass=null) {
|
}
|
||||||
$options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 );
|
*/
|
||||||
$protection = 192;
|
|
||||||
foreach($permissions as $permission){
|
/**
|
||||||
if (!isset($options[$permission]))
|
* Function to set permissions as well as user and owner passwords
|
||||||
$this->Error('Incorrect permission: '.$permission);
|
*
|
||||||
$protection += $options[$permission];
|
* - permissions is an array with values taken from the following list:
|
||||||
}
|
* 40bit: copy, print, modify, annot-forms
|
||||||
if ($owner_pass === null)
|
* 128bit: fill-in, screenreaders, assemble, degraded-print
|
||||||
$owner_pass = uniqid(rand());
|
* If a value is present it means that the permission is granted
|
||||||
$this->encrypted = true;
|
* - If a user password is set, user will be prompted before document is opened
|
||||||
$this->_generateencryptionkey($user_pass, $owner_pass, $protection);
|
* - If an owner password is set, document can be opened in privilege mode with no
|
||||||
}
|
* restriction if that password is entered
|
||||||
|
*/
|
||||||
|
function SetProtection($permissions=array(), $user_pass='', $owner_pass=null) {
|
||||||
function _putstream($s) {
|
$options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 );
|
||||||
if ($this->encrypted) {
|
$protection = 192;
|
||||||
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
|
foreach($permissions as $permission){
|
||||||
}
|
if (!isset($options[$permission]))
|
||||||
parent::_putstream($s);
|
$this->Error('Incorrect permission: '.$permission);
|
||||||
}
|
$protection += $options[$permission];
|
||||||
|
}
|
||||||
|
if ($owner_pass === null)
|
||||||
function _textstring($s) {
|
$owner_pass = uniqid(rand());
|
||||||
if ($this->encrypted) {
|
$this->encrypted = true;
|
||||||
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
|
$this->_generateencryptionkey($user_pass, $owner_pass, $protection);
|
||||||
}
|
}
|
||||||
return parent::_textstring($s);
|
|
||||||
}
|
|
||||||
|
function _putstream($s) {
|
||||||
|
if ($this->encrypted) {
|
||||||
/**
|
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
|
||||||
* Compute key depending on object number where the encrypted data is stored
|
}
|
||||||
*/
|
parent::_putstream($s);
|
||||||
function _objectkey($n) {
|
}
|
||||||
return substr($this->_md5_16($this->encryption_key.pack('VXxx', $n)), 0, 10);
|
|
||||||
}
|
|
||||||
|
function _textstring($s) {
|
||||||
|
if ($this->encrypted) {
|
||||||
/**
|
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
|
||||||
* Escape special characters
|
}
|
||||||
*/
|
return parent::_textstring($s);
|
||||||
function _escape($s) {
|
}
|
||||||
return str_replace(
|
|
||||||
array('\\',')','(',"\r", "\n", "\t"),
|
|
||||||
array('\\\\','\\)','\\(','\\r', '\\n', '\\t'),$s);
|
/**
|
||||||
}
|
* Compute key depending on object number where the encrypted data is stored
|
||||||
|
*/
|
||||||
function _putresources() {
|
function _objectkey($n) {
|
||||||
parent::_putresources();
|
return substr($this->_md5_16($this->encryption_key.pack('VXxx', $n)), 0, 10);
|
||||||
if ($this->encrypted) {
|
}
|
||||||
$this->_newobj();
|
|
||||||
$this->enc_obj_id = $this->_current_obj_id;
|
|
||||||
$this->_out('<<');
|
/**
|
||||||
$this->_putencryption();
|
* Escape special characters
|
||||||
$this->_out('>>');
|
*/
|
||||||
}
|
function _escape($s) {
|
||||||
}
|
return str_replace(
|
||||||
|
array('\\',')','(',"\r", "\n", "\t"),
|
||||||
function _putencryption() {
|
array('\\\\','\\)','\\(','\\r', '\\n', '\\t'),$s);
|
||||||
$this->_out('/Filter /Standard');
|
}
|
||||||
$this->_out('/V 1');
|
|
||||||
$this->_out('/R 2');
|
function _putresources() {
|
||||||
$this->_out('/O ('.$this->_escape($this->Ovalue).')');
|
parent::_putresources();
|
||||||
$this->_out('/U ('.$this->_escape($this->Uvalue).')');
|
if ($this->encrypted) {
|
||||||
$this->_out('/P '.$this->Pvalue);
|
$this->_newobj();
|
||||||
}
|
$this->enc_obj_id = $this->_current_obj_id;
|
||||||
|
$this->_out('<<');
|
||||||
|
$this->_putencryption();
|
||||||
function _puttrailer() {
|
$this->_out('>>');
|
||||||
parent::_puttrailer();
|
}
|
||||||
if ($this->encrypted) {
|
}
|
||||||
$this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
|
|
||||||
$this->_out('/ID [()()]');
|
function _putencryption() {
|
||||||
}
|
$this->_out('/Filter /Standard');
|
||||||
}
|
$this->_out('/V 1');
|
||||||
|
$this->_out('/R 2');
|
||||||
|
$this->_out('/O ('.$this->_escape($this->Ovalue).')');
|
||||||
/**
|
$this->_out('/U ('.$this->_escape($this->Uvalue).')');
|
||||||
* RC4 is the standard encryption algorithm used in PDF format
|
$this->_out('/P '.$this->Pvalue);
|
||||||
*/
|
}
|
||||||
function _RC4($key, $text) {
|
|
||||||
if ($this->last_rc4_key != $key) {
|
|
||||||
$k = str_repeat($key, 256/strlen($key)+1);
|
function _puttrailer() {
|
||||||
$rc4 = range(0,255);
|
parent::_puttrailer();
|
||||||
$j = 0;
|
if ($this->encrypted) {
|
||||||
for ($i=0; $i<256; $i++){
|
$this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
|
||||||
$t = $rc4[$i];
|
$this->_out('/ID [()()]');
|
||||||
$j = ($j + $t + ord($k{$i})) % 256;
|
}
|
||||||
$rc4[$i] = $rc4[$j];
|
}
|
||||||
$rc4[$j] = $t;
|
|
||||||
}
|
|
||||||
$this->last_rc4_key = $key;
|
/**
|
||||||
$this->last_rc4_key_c = $rc4;
|
* RC4 is the standard encryption algorithm used in PDF format
|
||||||
} else {
|
*/
|
||||||
$rc4 = $this->last_rc4_key_c;
|
function _RC4($key, $text) {
|
||||||
}
|
if ($this->last_rc4_key != $key) {
|
||||||
|
$k = str_repeat($key, 256/strlen($key)+1);
|
||||||
$len = strlen($text);
|
$rc4 = range(0,255);
|
||||||
$a = 0;
|
$j = 0;
|
||||||
$b = 0;
|
for ($i=0; $i<256; $i++){
|
||||||
$out = '';
|
$t = $rc4[$i];
|
||||||
for ($i=0; $i<$len; $i++){
|
$j = ($j + $t + ord($k{$i})) % 256;
|
||||||
$a = ($a+1)%256;
|
$rc4[$i] = $rc4[$j];
|
||||||
$t= $rc4[$a];
|
$rc4[$j] = $t;
|
||||||
$b = ($b+$t)%256;
|
}
|
||||||
$rc4[$a] = $rc4[$b];
|
$this->last_rc4_key = $key;
|
||||||
$rc4[$b] = $t;
|
$this->last_rc4_key_c = $rc4;
|
||||||
$k = $rc4[($rc4[$a]+$rc4[$b])%256];
|
} else {
|
||||||
$out.=chr(ord($text{$i}) ^ $k);
|
$rc4 = $this->last_rc4_key_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
$len = strlen($text);
|
||||||
}
|
$a = 0;
|
||||||
|
$b = 0;
|
||||||
|
$out = '';
|
||||||
/**
|
for ($i=0; $i<$len; $i++){
|
||||||
* Get MD5 as binary string
|
$a = ($a+1)%256;
|
||||||
*/
|
$t= $rc4[$a];
|
||||||
function _md5_16($string) {
|
$b = ($b+$t)%256;
|
||||||
return pack('H*',md5($string));
|
$rc4[$a] = $rc4[$b];
|
||||||
}
|
$rc4[$b] = $t;
|
||||||
|
$k = $rc4[($rc4[$a]+$rc4[$b])%256];
|
||||||
/**
|
$out.=chr(ord($text{$i}) ^ $k);
|
||||||
* Compute O value
|
}
|
||||||
*/
|
|
||||||
function _Ovalue($user_pass, $owner_pass) {
|
return $out;
|
||||||
$tmp = $this->_md5_16($owner_pass);
|
}
|
||||||
$owner_RC4_key = substr($tmp,0,5);
|
|
||||||
return $this->_RC4($owner_RC4_key, $user_pass);
|
|
||||||
}
|
/**
|
||||||
|
* Get MD5 as binary string
|
||||||
|
*/
|
||||||
/**
|
function _md5_16($string) {
|
||||||
* Compute U value
|
return pack('H*',md5($string));
|
||||||
*/
|
}
|
||||||
function _Uvalue() {
|
|
||||||
return $this->_RC4($this->encryption_key, $this->padding);
|
/**
|
||||||
}
|
* Compute O value
|
||||||
|
*/
|
||||||
|
function _Ovalue($user_pass, $owner_pass) {
|
||||||
/**
|
$tmp = $this->_md5_16($owner_pass);
|
||||||
* Compute encryption key
|
$owner_RC4_key = substr($tmp,0,5);
|
||||||
*/
|
return $this->_RC4($owner_RC4_key, $user_pass);
|
||||||
function _generateencryptionkey($user_pass, $owner_pass, $protection) {
|
}
|
||||||
// Pad passwords
|
|
||||||
$user_pass = substr($user_pass.$this->padding,0,32);
|
|
||||||
$owner_pass = substr($owner_pass.$this->padding,0,32);
|
/**
|
||||||
// Compute O value
|
* Compute U value
|
||||||
$this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
|
*/
|
||||||
// Compute encyption key
|
function _Uvalue() {
|
||||||
$tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
|
return $this->_RC4($this->encryption_key, $this->padding);
|
||||||
$this->encryption_key = substr($tmp,0,5);
|
}
|
||||||
// Compute U value
|
|
||||||
$this->Uvalue = $this->_Uvalue();
|
|
||||||
// Compute P value
|
/**
|
||||||
$this->Pvalue = -(($protection^255)+1);
|
* Compute encryption key
|
||||||
}
|
*/
|
||||||
|
function _generateencryptionkey($user_pass, $owner_pass, $protection) {
|
||||||
|
// Pad passwords
|
||||||
function pdf_write_value(&$value) {
|
$user_pass = substr($user_pass.$this->padding,0,32);
|
||||||
switch ($value[0]) {
|
$owner_pass = substr($owner_pass.$this->padding,0,32);
|
||||||
case PDF_TYPE_STRING :
|
// Compute O value
|
||||||
if ($this->encrypted) {
|
$this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
|
||||||
$value[1] = $this->_unescape($value[1]);
|
// Compute encyption key
|
||||||
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
|
$tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
|
||||||
$value[1] = $this->_escape($value[1]);
|
$this->encryption_key = substr($tmp,0,5);
|
||||||
}
|
// Compute U value
|
||||||
break;
|
$this->Uvalue = $this->_Uvalue();
|
||||||
|
// Compute P value
|
||||||
case PDF_TYPE_STREAM :
|
$this->Pvalue = -(($protection^255)+1);
|
||||||
if ($this->encrypted) {
|
}
|
||||||
$value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
|
|
||||||
}
|
|
||||||
break;
|
function pdf_write_value(&$value) {
|
||||||
|
switch ($value[0]) {
|
||||||
case PDF_TYPE_HEX :
|
case PDF_TYPE_STRING :
|
||||||
|
if ($this->encrypted) {
|
||||||
if ($this->encrypted) {
|
$value[1] = $this->_unescape($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]);
|
$value[1] = $this->_escape($value[1]);
|
||||||
|
}
|
||||||
// remake hexstring of encrypted string
|
break;
|
||||||
$value[1] = $this->str2hex($value[1]);
|
|
||||||
}
|
case PDF_TYPE_STREAM :
|
||||||
break;
|
if ($this->encrypted) {
|
||||||
}
|
$value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
|
||||||
|
}
|
||||||
parent::pdf_write_value($value);
|
break;
|
||||||
}
|
|
||||||
|
case PDF_TYPE_HEX :
|
||||||
|
|
||||||
function hex2str($hex) {
|
if ($this->encrypted) {
|
||||||
return pack('H*', str_replace(array("\r","\n",' '),'', $hex));
|
$value[1] = $this->hex2str($value[1]);
|
||||||
}
|
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
|
||||||
|
|
||||||
function str2hex($str) {
|
// remake hexstring of encrypted string
|
||||||
return current(unpack('H*',$str));
|
$value[1] = $this->str2hex($value[1]);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
/**
|
}
|
||||||
* Deescape special characters
|
|
||||||
*/
|
parent::pdf_write_value($value);
|
||||||
function _unescape($s) {
|
}
|
||||||
$out = '';
|
|
||||||
for ($count = 0, $n = strlen($s); $count < $n; $count++) {
|
|
||||||
if ($s[$count] != '\\' || $count == $n-1) {
|
function hex2str($hex) {
|
||||||
$out .= $s[$count];
|
return pack('H*', str_replace(array("\r","\n",' '),'', $hex));
|
||||||
} else {
|
}
|
||||||
switch ($s[++$count]) {
|
|
||||||
case ')':
|
function str2hex($str) {
|
||||||
case '(':
|
return current(unpack('H*',$str));
|
||||||
case '\\':
|
}
|
||||||
$out .= $s[$count];
|
|
||||||
break;
|
/**
|
||||||
case 'f':
|
* Deescape special characters
|
||||||
$out .= chr(0x0C);
|
*/
|
||||||
break;
|
function _unescape($s) {
|
||||||
case 'b':
|
$out = '';
|
||||||
$out .= chr(0x08);
|
for ($count = 0, $n = strlen($s); $count < $n; $count++) {
|
||||||
break;
|
if ($s[$count] != '\\' || $count == $n-1) {
|
||||||
case 't':
|
$out .= $s[$count];
|
||||||
$out .= chr(0x09);
|
} else {
|
||||||
break;
|
switch ($s[++$count]) {
|
||||||
case 'r':
|
case ')':
|
||||||
$out .= chr(0x0D);
|
case '(':
|
||||||
break;
|
case '\\':
|
||||||
case 'n':
|
$out .= $s[$count];
|
||||||
$out .= chr(0x0A);
|
break;
|
||||||
break;
|
case 'f':
|
||||||
case "\r":
|
$out .= chr(0x0C);
|
||||||
if ($count != $n-1 && $s[$count+1] == "\n")
|
break;
|
||||||
$count++;
|
case 'b':
|
||||||
break;
|
$out .= chr(0x08);
|
||||||
case "\n":
|
break;
|
||||||
break;
|
case 't':
|
||||||
default:
|
$out .= chr(0x09);
|
||||||
// Octal-Values
|
break;
|
||||||
if (ord($s[$count]) >= ord('0') &&
|
case 'r':
|
||||||
ord($s[$count]) <= ord('9')) {
|
$out .= chr(0x0D);
|
||||||
$oct = ''. $s[$count];
|
break;
|
||||||
|
case 'n':
|
||||||
if (ord($s[$count+1]) >= ord('0') &&
|
$out .= chr(0x0A);
|
||||||
ord($s[$count+1]) <= ord('9')) {
|
break;
|
||||||
$oct .= $s[++$count];
|
case "\r":
|
||||||
|
if ($count != $n-1 && $s[$count+1] == "\n")
|
||||||
if (ord($s[$count+1]) >= ord('0') &&
|
$count++;
|
||||||
ord($s[$count+1]) <= ord('9')) {
|
break;
|
||||||
$oct .= $s[++$count];
|
case "\n":
|
||||||
}
|
break;
|
||||||
}
|
default:
|
||||||
|
// Octal-Values
|
||||||
$out .= chr(octdec($oct));
|
if (ord($s[$count]) >= ord('0') &&
|
||||||
} else {
|
ord($s[$count]) <= ord('9')) {
|
||||||
$out .= $s[$count];
|
$oct = ''. $s[$count];
|
||||||
}
|
|
||||||
}
|
if (ord($s[$count+1]) >= ord('0') &&
|
||||||
}
|
ord($s[$count+1]) <= ord('9')) {
|
||||||
}
|
$oct .= $s[++$count];
|
||||||
return $out;
|
|
||||||
}
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user