ameters (width, height) to calculate the other one automatically in view to the aspect * ratio. * * @param mixed $tpl The template id * @param float|int|null $width The width. * @param float|int|null $height The height. * @return array|bool An array with following keys: width, height, 0 (=width), 1 (=height), orientation (L or P) */ public function getTemplateSize($tpl, $width = null, $height = null) { return $this->getImportedPageSize($tpl, $width, $height); } /** * @throws CrossReferenceException * @throws PdfTypeException * @throws \setasign\Fpdi\PdfParser\PdfParserException */ public function writeImportedPagesAndResolvedObjects() { $this->currentReaderId = null; foreach ($this->importedPages as $key => $pageData) { $this->writer->object(); $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; } public function getImportedPages() { return $this->importedPages; } protected function _put($s, $newLine = true) { if ($newLine) { $this->buffer .= $s . "\n"; } else { $this->buffer .= $s; } } /** * Writes a PdfType object to the resulting buffer. * * @param PdfType $value * @throws PdfTypeException */ public function writePdfType(PdfType $value) { if (!$this->encrypted) { if ($value instanceof PdfIndirectObject) { /** * @var $value PdfIndirectObject */ $n = $this->objectMap[$this->currentReaderId][$value->objectNumber]; $this->writer->object($n); $this->writePdfType($value->value); $this->_put('endobj'); return; } $this->fpdiWritePdfType($value); return; } if ($value instanceof PdfString) { $string = PdfString::unescape($value->value); $string = $this->protection->rc4($this->protection->objectKey($this->currentObjectNumber), $string); $value->value = $this->writer->escape($string); } elseif ($value instanceof PdfHexString) { $filter = new AsciiHex(); $string = $filter->decode($value->value); $string = $this->protection->rc4($this->protection->objectKey($this->currentObjectNumber), $string); $value->value = $filter->encode($string, true); } elseif ($value instanceof PdfStream) { $stream = $value->getStream(); $stream = $this->protection->rc4($this->protection->objectKey($this->currentObjectNumber), $stream); $dictionary = $value->value; $dictionary->value['Length'] = PdfNumeric::create(\strlen($stream)); $value = PdfStream::create($dictionary, $stream); } elseif ($value instanceof PdfIndirectObject) { /** * @var $value PdfIndirectObject */ $this->currentObjectNumber = $this->objectMap[$this->currentReaderId][$value->objectNumber]; /** * @var $value PdfIndirectObject */ $n = $this->objectMap[$this->currentReaderId][$value->objectNumber]; $this->writer->object($n); $this->writePdfType($value->value); $this->_put('endobj'); return; } $this->fpdiWritePdfType($value); } }