Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| StructTreeRoot | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
7.01 | |
0.00% |
0 / 1 |
| toPdf | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
7.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfNumber; |
| 11 | use Phpdftk\Pdf\Core\PdfObject; |
| 12 | use Phpdftk\Pdf\Core\PdfReference; |
| 13 | use Phpdftk\Pdf\Core\PdfVersion; |
| 14 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 15 | |
| 16 | /** |
| 17 | * PDF Structure Tree Root (ISO 32000-2 Table 323). |
| 18 | * |
| 19 | * Root of the structure tree for tagged PDF documents. |
| 20 | * |
| 21 | * Example: |
| 22 | * $root = new StructTreeRoot(); |
| 23 | * $root->k = new PdfReference($rootElem->objectNumber); |
| 24 | * $root->roleMap = new PdfDictionary(['Figure' => new PdfName('Span')]); |
| 25 | */ |
| 26 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 27 | class StructTreeRoot extends PdfObject |
| 28 | { |
| 29 | public const PDF_TYPE = 'StructTreeRoot'; |
| 30 | |
| 31 | public PdfReference|PdfArray|null $k = null; // /K - structure element(s) |
| 32 | public ?PdfReference $idTree = null; // /IDTree - name tree of IDs |
| 33 | public ?PdfReference $parentTree = null; // /ParentTree - number tree |
| 34 | public ?int $parentTreeNextKey = null; // /ParentTreeNextKey |
| 35 | public RoleMap|PdfDictionary|null $roleMap = null; // /RoleMap |
| 36 | public ClassMap|PdfDictionary|null $classMap = null; // /ClassMap |
| 37 | |
| 38 | public function toPdf(): string |
| 39 | { |
| 40 | $dict = new PdfDictionary(); |
| 41 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 42 | |
| 43 | if ($this->k !== null) { |
| 44 | $dict->set('K', $this->k); |
| 45 | } |
| 46 | if ($this->idTree !== null) { |
| 47 | $dict->set('IDTree', $this->idTree); |
| 48 | } |
| 49 | if ($this->parentTree !== null) { |
| 50 | $dict->set('ParentTree', $this->parentTree); |
| 51 | } |
| 52 | if ($this->parentTreeNextKey !== null) { |
| 53 | $dict->set('ParentTreeNextKey', new PdfNumber($this->parentTreeNextKey)); |
| 54 | } |
| 55 | if ($this->roleMap !== null) { |
| 56 | $dict->set('RoleMap', $this->roleMap); |
| 57 | } |
| 58 | if ($this->classMap !== null) { |
| 59 | $dict->set('ClassMap', $this->classMap); |
| 60 | } |
| 61 | |
| 62 | return $dict->toPdf(); |
| 63 | } |
| 64 | } |