Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
82.35% covered (warning)
82.35%
14 / 17
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
AcroForm
82.35% covered (warning)
82.35%
14 / 17
0.00% covered (danger)
0.00%
0 / 1
8.35
0.00% covered (danger)
0.00%
0 / 1
 toPdf
82.35% covered (warning)
82.35%
14 / 17
0.00% covered (danger)
0.00%
0 / 1
8.35
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Interactive\Form;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfBoolean;
9use Phpdftk\Pdf\Core\PdfDictionary;
10use Phpdftk\Pdf\Core\PdfNumber;
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;
16
17/**
18 * Interactive form (AcroForm) dictionary.
19 * Referenced from the document Catalog's /AcroForm entry.
20 */
21#[RequiresPdfVersion(PdfVersion::V1_2)]
22class AcroForm extends PdfObject
23{
24    /** @var array<int, PdfReference> */
25    public array $fields = [];               // /Fields - required (array of PdfReference)
26    public ?bool $needAppearances = null;    // /NeedAppearances
27    public ?int $sigFlags = null;            // /SigFlags
28    public ?PdfArray $co = null;             // /CO - calculation order
29    public ?PdfDictionary $dr = null;        // /DR - default resources
30    public ?PdfString $da = null;            // /DA - default appearance
31    public ?int $q = null;                   // /Q - justification
32    public ?PdfReference $xfa = null;        // /XFA
33
34    public function toPdf(): string
35    {
36        $dict = new PdfDictionary();
37        $dict->set('Fields', new PdfArray($this->fields));
38
39        if ($this->needAppearances !== null) {
40            $dict->set('NeedAppearances', new PdfBoolean($this->needAppearances));
41        }
42        if ($this->sigFlags !== null) {
43            $dict->set('SigFlags', new PdfNumber($this->sigFlags));
44        }
45        if ($this->co !== null) {
46            $dict->set('CO', $this->co);
47        }
48        if ($this->dr !== null) {
49            $dict->set('DR', $this->dr);
50        }
51        if ($this->da !== null) {
52            $dict->set('DA', $this->da);
53        }
54        if ($this->q !== null) {
55            $dict->set('Q', new PdfNumber($this->q));
56        }
57        if ($this->xfa !== null) {
58            $dict->set('XFA', $this->xfa);
59        }
60
61        return $dict->toPdf();
62    }
63}