|
9 | 9 | * @copyright YetiForce Sp. z o.o
|
10 | 10 | * @license MIT
|
11 | 11 | * @author Rafal Pospiech <r.pospiech@yetiforce.com>
|
| 12 | + * @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com> |
12 | 13 | */
|
13 | 14 |
|
14 | 15 | namespace YetiForcePDF;
|
@@ -871,21 +872,34 @@ public function parse()
|
871 | 872 | */
|
872 | 873 | public function render(): string
|
873 | 874 | {
|
874 |
| - $this->buffer = ''; |
| 875 | + $xref = $this->buffer = ''; |
875 | 876 | $this->buffer .= $this->getDocumentHeader();
|
876 | 877 | $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; |
881 | 879 | 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)); |
883 | 882 | $this->buffer .= $object->render() . "\n";
|
| 883 | + ++$objectSize; |
884 | 884 | }
|
885 | 885 | }
|
| 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 | + ]); |
886 | 901 | $this->buffer .= $this->getDocumentFooter();
|
887 | 902 | $this->removeObject($trailer);
|
888 |
| - |
889 | 903 | return $this->buffer;
|
890 | 904 | }
|
891 | 905 |
|
|
0 commit comments