Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Outline | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| toPdf | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfNumber; |
| 10 | use Phpdftk\Pdf\Core\PdfObject; |
| 11 | use Phpdftk\Pdf\Core\PdfReference; |
| 12 | use Phpdftk\Pdf\Core\PdfVersion; |
| 13 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 14 | |
| 15 | /** |
| 16 | * PDF Outlines dictionary (/Type /Outlines). |
| 17 | * |
| 18 | * The root of the document outline (bookmarks) tree. |
| 19 | * Referenced from the Catalog /Outlines field. |
| 20 | */ |
| 21 | #[RequiresPdfVersion(PdfVersion::V1_1)] |
| 22 | class Outline extends PdfObject |
| 23 | { |
| 24 | public const PDF_TYPE = 'Outlines'; |
| 25 | |
| 26 | public ?PdfReference $first = null; // /First - first top-level outline item |
| 27 | public ?PdfReference $last = null; // /Last - last top-level outline item |
| 28 | public int $count = 0; // /Count - total visible outline items |
| 29 | |
| 30 | public function toPdf(): string |
| 31 | { |
| 32 | $dict = new PdfDictionary(); |
| 33 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 34 | |
| 35 | if ($this->first !== null) { |
| 36 | $dict->set('First', $this->first); |
| 37 | } |
| 38 | if ($this->last !== null) { |
| 39 | $dict->set('Last', $this->last); |
| 40 | } |
| 41 | if ($this->count !== 0) { |
| 42 | $dict->set('Count', new PdfNumber($this->count)); |
| 43 | } |
| 44 | |
| 45 | return $dict->toPdf(); |
| 46 | } |
| 47 | } |