Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DPartRoot | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
5.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
4.02 | |||
| 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 | * Document parts root (/Type /DPartRoot) — ISO 32000-2 §14.12. |
| 18 | * |
| 19 | * Referenced from `Catalog::$dPartRoot`. Defines the document-part |
| 20 | * hierarchy and the names used for DPart metadata (e.g., for PDF/VT |
| 21 | * variable-data printing). |
| 22 | */ |
| 23 | #[RequiresPdfVersion(PdfVersion::V2_0)] |
| 24 | class DPartRoot extends PdfObject |
| 25 | { |
| 26 | public const PDF_TYPE = 'DPartRoot'; |
| 27 | |
| 28 | public PdfReference $dPartRootNode; // /DPartRootNode - required |
| 29 | public ?PdfArray $nodeNameList = null; // /NodeNameList |
| 30 | public ?int $recordLevel = null; // /RecordLevel |
| 31 | public ?PdfArray $recordPropertiesList = null; // /RecordPropertiesList |
| 32 | |
| 33 | public function __construct(PdfReference $dPartRootNode) |
| 34 | { |
| 35 | $this->dPartRootNode = $dPartRootNode; |
| 36 | } |
| 37 | |
| 38 | public function toPdf(): string |
| 39 | { |
| 40 | $dict = new PdfDictionary(); |
| 41 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 42 | $dict->set('DPartRootNode', $this->dPartRootNode); |
| 43 | if ($this->nodeNameList !== null) { |
| 44 | $dict->set('NodeNameList', $this->nodeNameList); |
| 45 | } |
| 46 | if ($this->recordLevel !== null) { |
| 47 | $dict->set('RecordLevel', new PdfNumber($this->recordLevel)); |
| 48 | } |
| 49 | if ($this->recordPropertiesList !== null) { |
| 50 | $dict->set('RecordPropertiesList', $this->recordPropertiesList); |
| 51 | } |
| 52 | return $dict->toPdf(); |
| 53 | } |
| 54 | } |