123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace Fpdi;
- use Fpdi\PdfParser\CrossReference\CrossReferenceException;
- use Fpdi\PdfParser\PdfParserException;
- use Fpdi\PdfParser\Type\PdfIndirectObject;
- use Fpdi\PdfParser\Type\PdfNull;
- class Fpdi extends FpdfTpl
- {
- use FpdiTrait;
-
- const VERSION = '2.3.6';
- protected function _enddoc()
- {
- parent::_enddoc();
- $this->cleanUp();
- }
-
- public function useTemplate($tpl, $x = 0, $y = 0, $width = null, $height = null, $adjustPageSize = false)
- {
- if (isset($this->importedPages[$tpl])) {
- $size = $this->useImportedPage($tpl, $x, $y, $width, $height, $adjustPageSize);
- if ($this->currentTemplateId !== null) {
- $this->templates[$this->currentTemplateId]['resources']['templates']['importedPages'][$tpl] = $tpl;
- }
- return $size;
- }
- return parent::useTemplate($tpl, $x, $y, $width, $height, $adjustPageSize);
- }
-
- public function getTemplateSize($tpl, $width = null, $height = null)
- {
- $size = parent::getTemplateSize($tpl, $width, $height);
- if ($size === false) {
- return $this->getImportedPageSize($tpl, $width, $height);
- }
- return $size;
- }
-
- protected function _putimages()
- {
- $this->currentReaderId = null;
- parent::_putimages();
- foreach ($this->importedPages as $key => $pageData) {
- $this->_newobj();
- $this->importedPages[$key]['objectNumber'] = $this->n;
- $this->currentReaderId = $pageData['readerId'];
- $this->writePdfType($pageData['stream']);
- $this->_put('endobj');
- }
- foreach (\array_keys($this->readers) as $readerId) {
- $parser = $this->getPdfReader($readerId)->getParser();
- $this->currentReaderId = $readerId;
- while (($objectNumber = \array_pop($this->objectsToCopy[$readerId])) !== null) {
- try {
- $object = $parser->getIndirectObject($objectNumber);
- } catch (CrossReferenceException $e) {
- if ($e->getCode() === CrossReferenceException::OBJECT_NOT_FOUND) {
- $object = PdfIndirectObject::create($objectNumber, 0, new PdfNull());
- } else {
- throw $e;
- }
- }
- $this->writePdfType($object);
- }
- }
- $this->currentReaderId = null;
- }
-
- protected function _putxobjectdict()
- {
- foreach ($this->importedPages as $key => $pageData) {
- $this->_put('/' . $pageData['id'] . ' ' . $pageData['objectNumber'] . ' 0 R');
- }
- parent::_putxobjectdict();
- }
-
- protected function _put($s, $newLine = true)
- {
- if ($newLine) {
- $this->buffer .= $s . "\n";
- } else {
- $this->buffer .= $s;
- }
- }
- }
|