|
@@ -44,7 +44,7 @@ class FPDI extends FPDF_TPL
|
|
* @var fpdi_pdf_parser[]
|
|
* @var fpdi_pdf_parser[]
|
|
*/
|
|
*/
|
|
public $parsers = array();
|
|
public $parsers = array();
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Current parser
|
|
* Current parser
|
|
*
|
|
*
|
|
@@ -65,7 +65,7 @@ class FPDI extends FPDF_TPL
|
|
* @var array
|
|
* @var array
|
|
*/
|
|
*/
|
|
protected $_objStack;
|
|
protected $_objStack;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Done object stack
|
|
* Done object stack
|
|
*
|
|
*
|
|
@@ -79,14 +79,14 @@ class FPDI extends FPDF_TPL
|
|
* @var integer
|
|
* @var integer
|
|
*/
|
|
*/
|
|
protected $_currentObjId;
|
|
protected $_currentObjId;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Cache for imported pages/template ids
|
|
* Cache for imported pages/template ids
|
|
*
|
|
*
|
|
* @var array
|
|
* @var array
|
|
*/
|
|
*/
|
|
protected $_importedPages = array();
|
|
protected $_importedPages = array();
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Set a source-file.
|
|
* Set a source-file.
|
|
*
|
|
*
|
|
@@ -103,7 +103,7 @@ class FPDI extends FPDF_TPL
|
|
$filename = $_filename;
|
|
$filename = $_filename;
|
|
|
|
|
|
$this->currentFilename = $filename;
|
|
$this->currentFilename = $filename;
|
|
-
|
|
|
|
|
|
+
|
|
if (!isset($this->parsers[$filename])) {
|
|
if (!isset($this->parsers[$filename])) {
|
|
$this->parsers[$filename] = $this->_getPdfParser($filename);
|
|
$this->parsers[$filename] = $this->_getPdfParser($filename);
|
|
$this->setPdfVersion(
|
|
$this->setPdfVersion(
|
|
@@ -112,10 +112,10 @@ class FPDI extends FPDF_TPL
|
|
}
|
|
}
|
|
|
|
|
|
$this->currentParser =& $this->parsers[$filename];
|
|
$this->currentParser =& $this->parsers[$filename];
|
|
-
|
|
|
|
|
|
+
|
|
return $this->parsers[$filename]->getPageCount();
|
|
return $this->parsers[$filename]->getPageCount();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns a PDF parser object
|
|
* Returns a PDF parser object
|
|
*
|
|
*
|
|
@@ -127,7 +127,7 @@ class FPDI extends FPDF_TPL
|
|
require_once('fpdi_pdf_parser.php');
|
|
require_once('fpdi_pdf_parser.php');
|
|
return new fpdi_pdf_parser($filename);
|
|
return new fpdi_pdf_parser($filename);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Get the current PDF version.
|
|
* Get the current PDF version.
|
|
*
|
|
*
|
|
@@ -137,7 +137,7 @@ class FPDI extends FPDF_TPL
|
|
{
|
|
{
|
|
return $this->PDFVersion;
|
|
return $this->PDFVersion;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Set the PDF version.
|
|
* Set the PDF version.
|
|
*
|
|
*
|
|
@@ -147,7 +147,7 @@ class FPDI extends FPDF_TPL
|
|
{
|
|
{
|
|
$this->PDFVersion = sprintf('%.1F', $version);
|
|
$this->PDFVersion = sprintf('%.1F', $version);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Import a page.
|
|
* Import a page.
|
|
*
|
|
*
|
|
@@ -178,7 +178,7 @@ class FPDI extends FPDF_TPL
|
|
if ($this->_inTpl) {
|
|
if ($this->_inTpl) {
|
|
throw new LogicException('Please import the desired pages before creating a new template.');
|
|
throw new LogicException('Please import the desired pages before creating a new template.');
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$fn = $this->currentFilename;
|
|
$fn = $this->currentFilename;
|
|
$boxName = '/' . ltrim($boxName, '/');
|
|
$boxName = '/' . ltrim($boxName, '/');
|
|
|
|
|
|
@@ -187,16 +187,16 @@ class FPDI extends FPDF_TPL
|
|
if (isset($this->_importedPages[$pageKey])) {
|
|
if (isset($this->_importedPages[$pageKey])) {
|
|
return $this->_importedPages[$pageKey];
|
|
return $this->_importedPages[$pageKey];
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$parser = $this->parsers[$fn];
|
|
$parser = $this->parsers[$fn];
|
|
$parser->setPageNo($pageNo);
|
|
$parser->setPageNo($pageNo);
|
|
|
|
|
|
if (!in_array($boxName, $parser->availableBoxes)) {
|
|
if (!in_array($boxName, $parser->availableBoxes)) {
|
|
throw new InvalidArgumentException(sprintf('Unknown box: %s', $boxName));
|
|
throw new InvalidArgumentException(sprintf('Unknown box: %s', $boxName));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$pageBoxes = $parser->getPageBoxes($pageNo, $this->k);
|
|
$pageBoxes = $parser->getPageBoxes($pageNo, $this->k);
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* MediaBox
|
|
* MediaBox
|
|
* CropBox: Default -> MediaBox
|
|
* CropBox: Default -> MediaBox
|
|
@@ -208,14 +208,14 @@ class FPDI extends FPDF_TPL
|
|
$boxName = '/CropBox';
|
|
$boxName = '/CropBox';
|
|
if (!isset($pageBoxes[$boxName]) && $boxName == '/CropBox')
|
|
if (!isset($pageBoxes[$boxName]) && $boxName == '/CropBox')
|
|
$boxName = '/MediaBox';
|
|
$boxName = '/MediaBox';
|
|
-
|
|
|
|
|
|
+
|
|
if (!isset($pageBoxes[$boxName]))
|
|
if (!isset($pageBoxes[$boxName]))
|
|
return false;
|
|
return false;
|
|
-
|
|
|
|
|
|
+
|
|
$this->lastUsedPageBox = $boxName;
|
|
$this->lastUsedPageBox = $boxName;
|
|
-
|
|
|
|
|
|
+
|
|
$box = $pageBoxes[$boxName];
|
|
$box = $pageBoxes[$boxName];
|
|
-
|
|
|
|
|
|
+
|
|
$this->tpl++;
|
|
$this->tpl++;
|
|
$this->_tpls[$this->tpl] = array();
|
|
$this->_tpls[$this->tpl] = array();
|
|
$tpl =& $this->_tpls[$this->tpl];
|
|
$tpl =& $this->_tpls[$this->tpl];
|
|
@@ -230,33 +230,33 @@ class FPDI extends FPDF_TPL
|
|
|
|
|
|
// To build an array that can be used by PDF_TPL::useTemplate()
|
|
// To build an array that can be used by PDF_TPL::useTemplate()
|
|
$this->_tpls[$this->tpl] = array_merge($this->_tpls[$this->tpl], $box);
|
|
$this->_tpls[$this->tpl] = array_merge($this->_tpls[$this->tpl], $box);
|
|
-
|
|
|
|
|
|
+
|
|
// An imported page will start at 0,0 all the time. Translation will be set in _putformxobjects()
|
|
// An imported page will start at 0,0 all the time. Translation will be set in _putformxobjects()
|
|
$tpl['x'] = 0;
|
|
$tpl['x'] = 0;
|
|
$tpl['y'] = 0;
|
|
$tpl['y'] = 0;
|
|
-
|
|
|
|
|
|
+
|
|
// handle rotated pages
|
|
// handle rotated pages
|
|
$rotation = $parser->getPageRotation($pageNo);
|
|
$rotation = $parser->getPageRotation($pageNo);
|
|
$tpl['_rotationAngle'] = 0;
|
|
$tpl['_rotationAngle'] = 0;
|
|
if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) {
|
|
if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) {
|
|
$steps = $angle / 90;
|
|
$steps = $angle / 90;
|
|
-
|
|
|
|
|
|
+
|
|
$_w = $tpl['w'];
|
|
$_w = $tpl['w'];
|
|
$_h = $tpl['h'];
|
|
$_h = $tpl['h'];
|
|
$tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
|
|
$tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
|
|
$tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
|
|
$tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
|
|
-
|
|
|
|
|
|
+
|
|
if ($angle < 0)
|
|
if ($angle < 0)
|
|
$angle += 360;
|
|
$angle += 360;
|
|
-
|
|
|
|
|
|
+
|
|
$tpl['_rotationAngle'] = $angle * -1;
|
|
$tpl['_rotationAngle'] = $angle * -1;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$this->_importedPages[$pageKey] = $this->tpl;
|
|
$this->_importedPages[$pageKey] = $this->tpl;
|
|
-
|
|
|
|
|
|
+
|
|
return $this->tpl;
|
|
return $this->tpl;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns the last used page boundary box.
|
|
* Returns the last used page boundary box.
|
|
*
|
|
*
|
|
@@ -295,12 +295,12 @@ class FPDI extends FPDF_TPL
|
|
$size = $this->getTemplateSize($tplIdx, $w, $h);
|
|
$size = $this->getTemplateSize($tplIdx, $w, $h);
|
|
$orientation = $size['w'] > $size['h'] ? 'L' : 'P';
|
|
$orientation = $size['w'] > $size['h'] ? 'L' : 'P';
|
|
$size = array($size['w'], $size['h']);
|
|
$size = array($size['w'], $size['h']);
|
|
-
|
|
|
|
|
|
+
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
|
$this->setPageFormat($size, $orientation);
|
|
$this->setPageFormat($size, $orientation);
|
|
} else {
|
|
} else {
|
|
$size = $this->_getpagesize($size);
|
|
$size = $this->_getpagesize($size);
|
|
-
|
|
|
|
|
|
+
|
|
if($orientation != $this->CurOrientation ||
|
|
if($orientation != $this->CurOrientation ||
|
|
$size[0] != $this->CurPageSize[0] ||
|
|
$size[0] != $this->CurPageSize[0] ||
|
|
$size[1] != $this->CurPageSize[1]
|
|
$size[1] != $this->CurPageSize[1]
|
|
@@ -320,16 +320,16 @@ class FPDI extends FPDF_TPL
|
|
$this->CurPageSize = $size;
|
|
$this->CurPageSize = $size;
|
|
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
|
|
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$this->_out('q 0 J 1 w 0 j 0 G 0 g'); // reset standard values
|
|
$this->_out('q 0 J 1 w 0 j 0 G 0 g'); // reset standard values
|
|
$size = parent::useTemplate($tplIdx, $x, $y, $w, $h);
|
|
$size = parent::useTemplate($tplIdx, $x, $y, $w, $h);
|
|
$this->_out('Q');
|
|
$this->_out('Q');
|
|
-
|
|
|
|
|
|
+
|
|
return $size;
|
|
return $size;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Copy all imported objects to the resulting document.
|
|
* Copy all imported objects to the resulting document.
|
|
*/
|
|
*/
|
|
@@ -373,33 +373,33 @@ class FPDI extends FPDF_TPL
|
|
foreach($this->_tpls AS $tplIdx => $tpl) {
|
|
foreach($this->_tpls AS $tplIdx => $tpl) {
|
|
$this->_newobj();
|
|
$this->_newobj();
|
|
$currentN = $this->n; // TCPDF/Protection: rem current "n"
|
|
$currentN = $this->n; // TCPDF/Protection: rem current "n"
|
|
-
|
|
|
|
|
|
+
|
|
$this->_tpls[$tplIdx]['n'] = $this->n;
|
|
$this->_tpls[$tplIdx]['n'] = $this->n;
|
|
$this->_out('<<' . $filter . '/Type /XObject');
|
|
$this->_out('<<' . $filter . '/Type /XObject');
|
|
$this->_out('/Subtype /Form');
|
|
$this->_out('/Subtype /Form');
|
|
$this->_out('/FormType 1');
|
|
$this->_out('/FormType 1');
|
|
-
|
|
|
|
- $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
|
|
|
|
|
+
|
|
|
|
+ $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
|
(isset($tpl['box']['llx']) ? $tpl['box']['llx'] : $tpl['x']) * $this->k,
|
|
(isset($tpl['box']['llx']) ? $tpl['box']['llx'] : $tpl['x']) * $this->k,
|
|
(isset($tpl['box']['lly']) ? $tpl['box']['lly'] : -$tpl['y']) * $this->k,
|
|
(isset($tpl['box']['lly']) ? $tpl['box']['lly'] : -$tpl['y']) * $this->k,
|
|
(isset($tpl['box']['urx']) ? $tpl['box']['urx'] : $tpl['w'] + $tpl['x']) * $this->k,
|
|
(isset($tpl['box']['urx']) ? $tpl['box']['urx'] : $tpl['w'] + $tpl['x']) * $this->k,
|
|
(isset($tpl['box']['ury']) ? $tpl['box']['ury'] : $tpl['h'] - $tpl['y']) * $this->k
|
|
(isset($tpl['box']['ury']) ? $tpl['box']['ury'] : $tpl['h'] - $tpl['y']) * $this->k
|
|
));
|
|
));
|
|
-
|
|
|
|
|
|
+
|
|
$c = 1;
|
|
$c = 1;
|
|
$s = 0;
|
|
$s = 0;
|
|
$tx = 0;
|
|
$tx = 0;
|
|
$ty = 0;
|
|
$ty = 0;
|
|
-
|
|
|
|
|
|
+
|
|
if (isset($tpl['box'])) {
|
|
if (isset($tpl['box'])) {
|
|
$tx = -$tpl['box']['llx'];
|
|
$tx = -$tpl['box']['llx'];
|
|
- $ty = -$tpl['box']['lly'];
|
|
|
|
-
|
|
|
|
|
|
+ $ty = -$tpl['box']['lly'];
|
|
|
|
+
|
|
if ($tpl['_rotationAngle'] <> 0) {
|
|
if ($tpl['_rotationAngle'] <> 0) {
|
|
$angle = $tpl['_rotationAngle'] * M_PI/180;
|
|
$angle = $tpl['_rotationAngle'] * M_PI/180;
|
|
$c = cos($angle);
|
|
$c = cos($angle);
|
|
$s = sin($angle);
|
|
$s = sin($angle);
|
|
-
|
|
|
|
|
|
+
|
|
switch($tpl['_rotationAngle']) {
|
|
switch($tpl['_rotationAngle']) {
|
|
case -90:
|
|
case -90:
|
|
$tx = -$tpl['box']['lly'];
|
|
$tx = -$tpl['box']['lly'];
|
|
@@ -419,16 +419,16 @@ class FPDI extends FPDF_TPL
|
|
$tx = -$tpl['x'] * 2;
|
|
$tx = -$tpl['x'] * 2;
|
|
$ty = $tpl['y'] * 2;
|
|
$ty = $tpl['y'] * 2;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$tx *= $this->k;
|
|
$tx *= $this->k;
|
|
$ty *= $this->k;
|
|
$ty *= $this->k;
|
|
-
|
|
|
|
|
|
+
|
|
if ($c != 1 || $s != 0 || $tx != 0 || $ty != 0) {
|
|
if ($c != 1 || $s != 0 || $tx != 0 || $ty != 0) {
|
|
$this->_out(sprintf('/Matrix [%.5F %.5F %.5F %.5F %.5F %.5F]',
|
|
$this->_out(sprintf('/Matrix [%.5F %.5F %.5F %.5F %.5F %.5F]',
|
|
$c, $s, -$s, $c, $tx, $ty
|
|
$c, $s, -$s, $c, $tx, $ty
|
|
));
|
|
));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$this->_out('/Resources ');
|
|
$this->_out('/Resources ');
|
|
|
|
|
|
if (isset($tpl['resources'])) {
|
|
if (isset($tpl['resources'])) {
|
|
@@ -484,7 +484,7 @@ class FPDI extends FPDF_TPL
|
|
$this->_out('endobj');
|
|
$this->_out('endobj');
|
|
$this->n = $newN; // TCPDF: reset to new "n"
|
|
$this->n = $newN; // TCPDF: reset to new "n"
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$this->_putimportedobjects();
|
|
$this->_putimportedobjects();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -509,7 +509,7 @@ class FPDI extends FPDF_TPL
|
|
$this->_out($objId . ' 0 obj');
|
|
$this->_out($objId . ' 0 obj');
|
|
$this->_currentObjId = $objId; // for later use with encryption
|
|
$this->_currentObjId = $objId; // for later use with encryption
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return $objId;
|
|
return $objId;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -525,7 +525,7 @@ class FPDI extends FPDF_TPL
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
|
if (is_subclass_of($this, 'TCPDF')) {
|
|
parent::_prepareValue($value);
|
|
parent::_prepareValue($value);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
switch ($value[0]) {
|
|
switch ($value[0]) {
|
|
|
|
|
|
case pdf_parser::TYPE_TOKEN:
|
|
case pdf_parser::TYPE_TOKEN:
|
|
@@ -539,7 +539,7 @@ class FPDI extends FPDF_TPL
|
|
$this->_straightOut($value[1] . ' ');
|
|
$this->_straightOut($value[1] . ' ');
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
-
|
|
|
|
|
|
+
|
|
case pdf_parser::TYPE_ARRAY:
|
|
case pdf_parser::TYPE_ARRAY:
|
|
|
|
|
|
// An array. Output the proper
|
|
// An array. Output the proper
|
|
@@ -600,7 +600,7 @@ class FPDI extends FPDF_TPL
|
|
$this->_out($value[2][1]);
|
|
$this->_out($value[2][1]);
|
|
$this->_straightOut("endstream");
|
|
$this->_straightOut("endstream");
|
|
break;
|
|
break;
|
|
-
|
|
|
|
|
|
+
|
|
case pdf_parser::TYPE_HEX:
|
|
case pdf_parser::TYPE_HEX:
|
|
$this->_straightOut('<' . $value[1] . '>');
|
|
$this->_straightOut('<' . $value[1] . '>');
|
|
break;
|
|
break;
|
|
@@ -608,7 +608,7 @@ class FPDI extends FPDF_TPL
|
|
case pdf_parser::TYPE_BOOLEAN:
|
|
case pdf_parser::TYPE_BOOLEAN:
|
|
$this->_straightOut($value[1] ? 'true ' : 'false ');
|
|
$this->_straightOut($value[1] ? 'true ' : 'false ');
|
|
break;
|
|
break;
|
|
-
|
|
|
|
|
|
+
|
|
case pdf_parser::TYPE_NULL:
|
|
case pdf_parser::TYPE_NULL:
|
|
// The null object.
|
|
// The null object.
|
|
|
|
|
|
@@ -616,8 +616,8 @@ class FPDI extends FPDF_TPL
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Modified _out() method so not each call will add a newline to the output.
|
|
* Modified _out() method so not each call will add a newline to the output.
|
|
*/
|
|
*/
|
|
@@ -664,7 +664,7 @@ class FPDI extends FPDF_TPL
|
|
parent::_enddoc();
|
|
parent::_enddoc();
|
|
$this->_closeParsers();
|
|
$this->_closeParsers();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Close all files opened by parsers.
|
|
* Close all files opened by parsers.
|
|
*
|
|
*
|
|
@@ -679,7 +679,7 @@ class FPDI extends FPDF_TPL
|
|
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Removes cycled references and closes the file handles of the parser objects.
|
|
* Removes cycled references and closes the file handles of the parser objects.
|
|
*/
|
|
*/
|