From 224f04aeb7c49754c36b11cd9aa85848a02cc717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Skrzypczak?= Date: Fri, 26 Nov 2021 10:10:00 +0100 Subject: [PATCH 1/2] Update README.MD --- README.MD | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.MD b/README.MD index 22f649f..499d426 100644 --- a/README.MD +++ b/README.MD @@ -16,7 +16,7 @@ $loader = require '../vendor/autoload.php'; $document = (new YetiForcePDF\Document())->init(); $document->loadHtml('
your html goes here
'); $pdfFile = $document->render(); -file_put_contents('YourPDFD.pdf', $pdfFile); +file_put_contents('YourPDF.pdf', $pdfFile); ``` ### Supported css rules @@ -193,8 +193,6 @@ When you want to place page number (in header or footer for example) you can do - [ ] basic transformations (rotateXY, scaleXY, translateXY) - [ ] position (absolute, relative) -### License -MIT -======= -file_put_contents('test.pdf', $pdfFile); -``` +## License + +Distributed under the MIT license. See LICENSE for details. From 4d85b0c4f333db47a4189e40699168815dc217ca Mon Sep 17 00:00:00 2001 From: Mariusz Krzaczkowski Date: Fri, 4 Feb 2022 13:52:02 +0100 Subject: [PATCH 2/2] Improved compliance with PDF-1.7 standard --- lib/Document.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/Document.php b/lib/Document.php index 91911d2..faf4a65 100644 --- a/lib/Document.php +++ b/lib/Document.php @@ -9,6 +9,7 @@ * @copyright YetiForce Sp. z o.o * @license MIT * @author Rafal Pospiech + * @author Mariusz Krzaczkowski */ namespace YetiForcePDF; @@ -871,21 +872,34 @@ public function parse() */ public function render(): string { - $this->buffer = ''; + $xref = $this->buffer = ''; $this->buffer .= $this->getDocumentHeader(); $this->parse(); - $trailer = (new \YetiForcePDF\Objects\Trailer()) - ->setDocument($this) - ->init(); - $trailer->setRootObject($this->catalog)->setSize(\count($this->objects) - 1); + $objectSize = 0; foreach ($this->objects as $object) { - if (\in_array($object->getBasicType(), ['Dictionary', 'Stream', 'Trailer', 'Array'])) { + if (\in_array($object->getBasicType(), ['Dictionary', 'Stream', 'Array'])) { + $xref .= sprintf("%010d 00000 n \n", \strlen($this->buffer)); $this->buffer .= $object->render() . "\n"; + ++$objectSize; } } + $offset = \strlen($this->buffer); + $this->buffer .= implode("\n", [ + 'xref', + '0 ' . ($objectSize + 1), + '0000000000 65535 f ', + $xref, + ]); + $trailer = (new \YetiForcePDF\Objects\Trailer()) + ->setDocument($this)->setRootObject($this->catalog)->setSize($objectSize); + $this->buffer .= $trailer->render() . "\n"; + $this->buffer .= implode("\n", [ + 'startxref', + $offset, + '', + ]); $this->buffer .= $this->getDocumentFooter(); $this->removeObject($trailer); - return $this->buffer; }