Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ViewerPreferences
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
1 / 1
19
100.00% covered (success)
100.00%
1 / 1
 toPdf
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
1 / 1
19
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\PdfNumber;
12use Phpdftk\Pdf\Core\PdfObject;
13use Phpdftk\Pdf\Core\PdfVersion;
14use Phpdftk\Pdf\Core\RequiresPdfVersion;
15
16/**
17 * PDF Viewer Preferences dictionary.
18 * Controls how the PDF viewer displays the document.
19 */
20class ViewerPreferences extends PdfObject
21{
22    public ?bool $hideToolbar = null;                      // /HideToolbar
23    public ?bool $hideMenubar = null;                      // /HideMenubar
24    public ?bool $hideWindowUI = null;                     // /HideWindowUI
25    public ?bool $fitWindow = null;                        // /FitWindow
26    public ?bool $centerWindow = null;                     // /CenterWindow
27    public ?bool $displayDocTitle = null;                  // /DisplayDocTitle
28    public ?PdfName $nonFullScreenPageMode = null;         // /NonFullScreenPageMode
29    public ?PdfName $direction = null;                     // /Direction
30    public ?PdfName $viewArea = null;                      // /ViewArea
31    public ?PdfName $viewClip = null;                      // /ViewClip
32    public ?PdfName $printArea = null;                     // /PrintArea
33    public ?PdfName $printClip = null;                     // /PrintClip
34    public ?PdfName $printScaling = null;                  // /PrintScaling
35    public ?PdfName $duplex = null;                        // /Duplex
36    public ?bool $pickTrayByPDFSize = null;                // /PickTrayByPDFSize
37    public ?PdfArray $printPageRange = null;               // /PrintPageRange
38    public ?int $numCopies = null;                         // /NumCopies
39    #[RequiresPdfVersion(PdfVersion::V2_0)]
40    public ?PdfArray $enforce = null;                      // /Enforce - PDF 2.0 array of names
41
42    public function toPdf(): string
43    {
44        $dict = new PdfDictionary();
45
46        if ($this->hideToolbar !== null) {
47            $dict->set('HideToolbar', new PdfBoolean($this->hideToolbar));
48        }
49        if ($this->hideMenubar !== null) {
50            $dict->set('HideMenubar', new PdfBoolean($this->hideMenubar));
51        }
52        if ($this->hideWindowUI !== null) {
53            $dict->set('HideWindowUI', new PdfBoolean($this->hideWindowUI));
54        }
55        if ($this->fitWindow !== null) {
56            $dict->set('FitWindow', new PdfBoolean($this->fitWindow));
57        }
58        if ($this->centerWindow !== null) {
59            $dict->set('CenterWindow', new PdfBoolean($this->centerWindow));
60        }
61        if ($this->displayDocTitle !== null) {
62            $dict->set('DisplayDocTitle', new PdfBoolean($this->displayDocTitle));
63        }
64        if ($this->nonFullScreenPageMode !== null) {
65            $dict->set('NonFullScreenPageMode', $this->nonFullScreenPageMode);
66        }
67        if ($this->direction !== null) {
68            $dict->set('Direction', $this->direction);
69        }
70        if ($this->viewArea !== null) {
71            $dict->set('ViewArea', $this->viewArea);
72        }
73        if ($this->viewClip !== null) {
74            $dict->set('ViewClip', $this->viewClip);
75        }
76        if ($this->printArea !== null) {
77            $dict->set('PrintArea', $this->printArea);
78        }
79        if ($this->printClip !== null) {
80            $dict->set('PrintClip', $this->printClip);
81        }
82        if ($this->printScaling !== null) {
83            $dict->set('PrintScaling', $this->printScaling);
84        }
85        if ($this->duplex !== null) {
86            $dict->set('Duplex', $this->duplex);
87        }
88        if ($this->pickTrayByPDFSize !== null) {
89            $dict->set('PickTrayByPDFSize', new PdfBoolean($this->pickTrayByPDFSize));
90        }
91        if ($this->printPageRange !== null) {
92            $dict->set('PrintPageRange', $this->printPageRange);
93        }
94        if ($this->numCopies !== null) {
95            $dict->set('NumCopies', new PdfNumber($this->numCopies));
96        }
97        if ($this->enforce !== null) {
98            $dict->set('Enforce', $this->enforce);
99        }
100
101        return $dict->toPdf();
102    }
103}