Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TrailerDictionary | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\File; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfNumber; |
| 10 | use Phpdftk\Pdf\Core\PdfReference; |
| 11 | use Phpdftk\Pdf\Core\Serializable; |
| 12 | |
| 13 | /** |
| 14 | * Trailer dictionary — ISO 32000-2 §7.5.5, Table 17. |
| 15 | * |
| 16 | * Carries the bookkeeping entries that follow the classic `trailer` |
| 17 | * keyword at the end of a PDF file: the total object count (/Size), the |
| 18 | * catalog reference (/Root), the optional info dict, file ID, previous |
| 19 | * xref offset (for incremental updates), and encrypt dict reference. |
| 20 | * |
| 21 | * Used by {@see PdfFileWriter} to emit the trailer section of a |
| 22 | * generated PDF. |
| 23 | */ |
| 24 | class TrailerDictionary implements Serializable |
| 25 | { |
| 26 | public int $size = 0; // /Size |
| 27 | public PdfReference $root; // /Root - required |
| 28 | public ?PdfReference $info = null; // /Info |
| 29 | public ?PdfReference $encrypt = null; // /Encrypt |
| 30 | public ?PdfArray $id = null; // /ID - 2-element byte-string array |
| 31 | public ?int $prev = null; // /Prev - byte offset of previous xref |
| 32 | |
| 33 | public function __construct(PdfReference $root) |
| 34 | { |
| 35 | $this->root = $root; |
| 36 | } |
| 37 | |
| 38 | public function toPdf(): string |
| 39 | { |
| 40 | $dict = new PdfDictionary(); |
| 41 | $dict->set('Size', new PdfNumber($this->size)); |
| 42 | $dict->set('Root', $this->root); |
| 43 | if ($this->info !== null) { |
| 44 | $dict->set('Info', $this->info); |
| 45 | } |
| 46 | if ($this->encrypt !== null) { |
| 47 | $dict->set('Encrypt', $this->encrypt); |
| 48 | } |
| 49 | if ($this->id !== null) { |
| 50 | $dict->set('ID', $this->id); |
| 51 | } |
| 52 | if ($this->prev !== null) { |
| 53 | $dict->set('Prev', new PdfNumber($this->prev)); |
| 54 | } |
| 55 | return $dict->toPdf(); |
| 56 | } |
| 57 | } |