Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
98.41% covered (success)
98.41%
62 / 63
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Catalog
98.41% covered (success)
98.41%
62 / 63
0.00% covered (danger)
0.00%
0 / 1
31
0.00% covered (danger)
0.00%
0 / 1
 toPdf
98.41% covered (success)
98.41%
62 / 63
0.00% covered (danger)
0.00%
0 / 1
31
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Document;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfBoolean;
9use Phpdftk\Pdf\Core\PdfDictionary;
10use Phpdftk\Pdf\Core\PdfName;
11use Phpdftk\Pdf\Core\PdfObject;
12use Phpdftk\Pdf\Core\PdfReference;
13use Phpdftk\Pdf\Core\PdfString;
14use Phpdftk\Pdf\Core\PdfVersion;
15use Phpdftk\Pdf\Core\RequiresPdfVersion;
16use Phpdftk\Pdf\Core\Serializable;
17
18/**
19 * PDF Document Catalog (/Type /Catalog).
20 * This is the root object of every PDF document.
21 */
22class Catalog extends PdfObject
23{
24    public const PDF_TYPE = 'Catalog';
25
26    public ?PdfReference $pages = null;              // /Pages - required
27    public ?PdfName $version = null;                 // /Version
28    public ?PdfReference $outlines = null;           // /Outlines
29    public ?PdfReference $names = null;              // /Names
30    public ?PdfReference $dests = null;              // /Dests
31    /**
32     * /ViewerPreferences — accepts an inline `PdfDictionary`, a
33     * `PdfReference` to a registered {@see ViewerPreferences} object,
34     * or the value itself when caller writes inline.
35     */
36    public Serializable|null $viewerPreferences = null;
37    public ?PdfName $pageLayout = null;              // /PageLayout
38    public ?PdfName $pageMode = null;                // /PageMode
39    public ?PdfReference $openAction = null;         // /OpenAction
40    public ?PdfReference $acroForm = null;           // /AcroForm
41    public ?PdfReference $metadata = null;           // /Metadata
42    public ?MarkInfo $markInfo = null;               // /MarkInfo
43    public ?PdfString $lang = null;                  // /Lang
44    public ?PdfReference $pageLabels = null;         // /PageLabels - number tree of PageLabel dicts
45    public ?PdfReference $aa = null;                 // /AA - additional actions dict
46    public ?PdfDictionary $uri = null;               // /URI - base URI dict
47    public ?PdfArray $outputIntents = null;           // /OutputIntents - array of OutputIntent refs
48    public ?PdfBoolean $needsRendering = null;       // /NeedsRendering - XFA flag
49    public ?PdfDictionary $legal = null;             // /Legal - legal attestation dict
50    public ?PdfReference $ocProperties = null;       // /OCProperties - optional content
51    public ?PdfDictionary $perms = null;             // /Perms - permissions dict
52    public ?PdfArray $requirements = null;           // /Requirements - requirements array
53    public ?PdfReference $collection = null;         // /Collection - PDF portfolio
54    public ?PdfReference $spiderInfo = null;         // /SpiderInfo - web capture info
55    public ?PdfDictionary $pieceInfo = null;         // /PieceInfo - application data
56    public ?PdfReference $structTreeRoot = null;     // /StructTreeRoot - structure tree root
57    #[RequiresPdfVersion(PdfVersion::V2_0)]
58    public DSS|PdfReference|null $dss = null;        // /DSS - document security store (PAdES LTV)
59    #[RequiresPdfVersion(PdfVersion::V1_7)]
60    public ?PdfDictionary $extensions = null;        // /Extensions - developer extensions
61    #[RequiresPdfVersion(PdfVersion::V2_0)]
62    public ?PdfArray $af = null;                     // /AF - associated files
63    #[RequiresPdfVersion(PdfVersion::V2_0)]
64    public ?PdfReference $dPartRoot = null;          // /DPartRoot - document parts root (PDF 2.0)
65
66    public function toPdf(): string
67    {
68        $dict = new PdfDictionary();
69        $dict->set('Type', new PdfName(self::PDF_TYPE));
70
71        if ($this->pages !== null) {
72            $dict->set('Pages', $this->pages);
73        }
74        if ($this->version !== null) {
75            $dict->set('Version', $this->version);
76        }
77        if ($this->outlines !== null) {
78            $dict->set('Outlines', $this->outlines);
79        }
80        if ($this->names !== null) {
81            $dict->set('Names', $this->names);
82        }
83        if ($this->dests !== null) {
84            $dict->set('Dests', $this->dests);
85        }
86        if ($this->viewerPreferences !== null) {
87            $dict->set('ViewerPreferences', $this->viewerPreferences);
88        }
89        if ($this->pageLayout !== null) {
90            $dict->set('PageLayout', $this->pageLayout);
91        }
92        if ($this->pageMode !== null) {
93            $dict->set('PageMode', $this->pageMode);
94        }
95        if ($this->openAction !== null) {
96            $dict->set('OpenAction', $this->openAction);
97        }
98        if ($this->acroForm !== null) {
99            $dict->set('AcroForm', $this->acroForm);
100        }
101        if ($this->metadata !== null) {
102            $dict->set('Metadata', $this->metadata);
103        }
104        if ($this->markInfo !== null) {
105            $dict->set('MarkInfo', $this->markInfo);
106        }
107        if ($this->lang !== null) {
108            $dict->set('Lang', $this->lang);
109        }
110        if ($this->pageLabels !== null) {
111            $dict->set('PageLabels', $this->pageLabels);
112        }
113        if ($this->aa !== null) {
114            $dict->set('AA', $this->aa);
115        }
116        if ($this->uri !== null) {
117            $dict->set('URI', $this->uri);
118        }
119        if ($this->outputIntents !== null) {
120            $dict->set('OutputIntents', $this->outputIntents);
121        }
122        if ($this->needsRendering !== null) {
123            $dict->set('NeedsRendering', $this->needsRendering);
124        }
125        if ($this->legal !== null) {
126            $dict->set('Legal', $this->legal);
127        }
128        if ($this->ocProperties !== null) {
129            $dict->set('OCProperties', $this->ocProperties);
130        }
131        if ($this->perms !== null) {
132            $dict->set('Perms', $this->perms);
133        }
134        if ($this->requirements !== null) {
135            $dict->set('Requirements', $this->requirements);
136        }
137        if ($this->collection !== null) {
138            $dict->set('Collection', $this->collection);
139        }
140        if ($this->spiderInfo !== null) {
141            $dict->set('SpiderInfo', $this->spiderInfo);
142        }
143        if ($this->pieceInfo !== null) {
144            $dict->set('PieceInfo', $this->pieceInfo);
145        }
146        if ($this->structTreeRoot !== null) {
147            $dict->set('StructTreeRoot', $this->structTreeRoot);
148        }
149        if ($this->dss !== null) {
150            $dict->set('DSS', $this->dss);
151        }
152        if ($this->extensions !== null) {
153            $dict->set('Extensions', $this->extensions);
154        }
155        if ($this->af !== null) {
156            $dict->set('AF', $this->af);
157        }
158        if ($this->dPartRoot !== null) {
159            $dict->set('DPartRoot', $this->dPartRoot);
160        }
161
162        return $dict->toPdf();
163    }
164}