Skip to content

Commit db74749

Browse files
Merge pull request #28 from YetiForceCompany/developer
dev
2 parents ba6173d + 4d85b0c commit db74749

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

README.MD

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $loader = require '../vendor/autoload.php';
1616
$document = (new YetiForcePDF\Document())->init();
1717
$document->loadHtml('<div style="text-align:center;">your html goes here</div>');
1818
$pdfFile = $document->render();
19-
file_put_contents('YourPDFD.pdf', $pdfFile);
19+
file_put_contents('YourPDF.pdf', $pdfFile);
2020
```
2121

2222
### Supported css rules
@@ -193,8 +193,6 @@ When you want to place page number (in header or footer for example) you can do
193193
- [ ] basic transformations (rotateXY, scaleXY, translateXY)
194194
- [ ] position (absolute, relative)
195195

196-
### License
197-
MIT
198-
=======
199-
file_put_contents('test.pdf', $pdfFile);
200-
```
196+
## License
197+
198+
Distributed under the MIT license. See LICENSE for details.

lib/Document.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @copyright YetiForce Sp. z o.o
1010
* @license MIT
1111
* @author Rafal Pospiech <r.pospiech@yetiforce.com>
12+
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
1213
*/
1314

1415
namespace YetiForcePDF;
@@ -871,21 +872,34 @@ public function parse()
871872
*/
872873
public function render(): string
873874
{
874-
$this->buffer = '';
875+
$xref = $this->buffer = '';
875876
$this->buffer .= $this->getDocumentHeader();
876877
$this->parse();
877-
$trailer = (new \YetiForcePDF\Objects\Trailer())
878-
->setDocument($this)
879-
->init();
880-
$trailer->setRootObject($this->catalog)->setSize(\count($this->objects) - 1);
878+
$objectSize = 0;
881879
foreach ($this->objects as $object) {
882-
if (\in_array($object->getBasicType(), ['Dictionary', 'Stream', 'Trailer', 'Array'])) {
880+
if (\in_array($object->getBasicType(), ['Dictionary', 'Stream', 'Array'])) {
881+
$xref .= sprintf("%010d 00000 n \n", \strlen($this->buffer));
883882
$this->buffer .= $object->render() . "\n";
883+
++$objectSize;
884884
}
885885
}
886+
$offset = \strlen($this->buffer);
887+
$this->buffer .= implode("\n", [
888+
'xref',
889+
'0 ' . ($objectSize + 1),
890+
'0000000000 65535 f ',
891+
$xref,
892+
]);
893+
$trailer = (new \YetiForcePDF\Objects\Trailer())
894+
->setDocument($this)->setRootObject($this->catalog)->setSize($objectSize);
895+
$this->buffer .= $trailer->render() . "\n";
896+
$this->buffer .= implode("\n", [
897+
'startxref',
898+
$offset,
899+
'',
900+
]);
886901
$this->buffer .= $this->getDocumentFooter();
887902
$this->removeObject($trailer);
888-
889903
return $this->buffer;
890904
}
891905

0 commit comments

Comments
 (0)