Skip to content

Commit

Permalink
Merge pull request #28 from YetiForceCompany/developer
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
mariuszkrzaczkowski authored Feb 4, 2022
2 parents ba6173d + 4d85b0c commit db74749
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
10 changes: 4 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $loader = require '../vendor/autoload.php';
$document = (new YetiForcePDF\Document())->init();
$document->loadHtml('<div style="text-align:center;">your html goes here</div>');
$pdfFile = $document->render();
file_put_contents('YourPDFD.pdf', $pdfFile);
file_put_contents('YourPDF.pdf', $pdfFile);
```

### Supported css rules
Expand Down Expand Up @@ -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.
28 changes: 21 additions & 7 deletions lib/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @copyright YetiForce Sp. z o.o
* @license MIT
* @author Rafal Pospiech <r.pospiech@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

namespace YetiForcePDF;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit db74749

Please sign in to comment.