3 // FPDI - Version 1.2.1
5 // Copyright 2004-2008 Setasign - Jan Slabon
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 * This class is used as a bridge between TCPDF and FPDI
22 * and will create the possibility to use both FPDF and TCPDF
23 * via one FPDI version.
25 * We'll simply remap TCPDF to FPDF again.
27 * It'll be loaded and extended by FPDF_TPL.
29 class FPDF extends TCPDF {
38 function __get($name) {
41 return $this->PDFVersion;
44 case 'lastUsedPageBox':
45 return $this->lastUsedPageBox;
47 return $this->pageNumber;
50 $this->Error('Cannot access protected property '.get_class($this).':$'.$name.' / Undefined property: '.get_class($this).'::$'.$name);
54 function __set($name, $value) {
57 $this->PDFVersion = $value;
61 $this->Error('Cannot access protected property '.get_class($this).':$'.$name.' / Undefined property: '.get_class($this).'::$'.$name);
66 * Encryption of imported data by FPDI
70 function pdf_write_value(&$value) {
72 case PDF_TYPE_STRING :
73 if ($this->encrypted) {
74 $value[1] = $this->_unescape($value[1]);
75 $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
76 $value[1] = $this->_escape($value[1]);
80 case PDF_TYPE_STREAM :
81 if ($this->encrypted) {
82 $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
87 if ($this->encrypted) {
88 $value[1] = $this->hex2str($value[1]);
89 $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
91 // remake hexstring of encrypted string
92 $value[1] = $this->str2hex($value[1]);
99 * Unescapes a PDF string
104 function _unescape($s) {
105 return strtr($s, array(
118 * Hexadecimal to string
123 function hex2str($hex) {
124 return pack("H*", str_replace(array("\r", "\n", " "), "", $hex));
128 * String to hexadecimal
133 function str2hex($str) {
134 return current(unpack("H*", $str));