Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Collection | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| toPdf | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfObject; |
| 10 | use Phpdftk\Pdf\Core\PdfReference; |
| 11 | use Phpdftk\Pdf\Core\PdfVersion; |
| 12 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 13 | |
| 14 | /** |
| 15 | * PDF Collection dictionary (ISO 32000-2 Table 152). |
| 16 | * |
| 17 | * Defines a PDF portfolio (collection of embedded files). |
| 18 | * |
| 19 | * Example: |
| 20 | * $collection = new Collection(); |
| 21 | * $collection->view = new PdfName('D'); |
| 22 | * $writer->register($collection); |
| 23 | */ |
| 24 | #[RequiresPdfVersion(PdfVersion::V1_7)] |
| 25 | class Collection extends PdfObject |
| 26 | { |
| 27 | public const PDF_TYPE = 'Collection'; |
| 28 | |
| 29 | public ?PdfReference $schema = null; // /Schema |
| 30 | public ?PdfName $d = null; // /D - default document |
| 31 | public ?PdfName $view = null; // /View (D, T, H) |
| 32 | public ?PdfReference $sort = null; // /Sort |
| 33 | |
| 34 | public function toPdf(): string |
| 35 | { |
| 36 | $dict = new PdfDictionary(); |
| 37 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 38 | |
| 39 | if ($this->schema !== null) { |
| 40 | $dict->set('Schema', $this->schema); |
| 41 | } |
| 42 | if ($this->d !== null) { |
| 43 | $dict->set('D', $this->d); |
| 44 | } |
| 45 | if ($this->view !== null) { |
| 46 | $dict->set('View', $this->view); |
| 47 | } |
| 48 | if ($this->sort !== null) { |
| 49 | $dict->set('Sort', $this->sort); |
| 50 | } |
| 51 | |
| 52 | return $dict->toPdf(); |
| 53 | } |
| 54 | } |