Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CollectionSchema | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 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\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * PDF Collection Schema dictionary. |
| 15 | * |
| 16 | * Defines the schema for collection fields in a PDF portfolio. |
| 17 | * |
| 18 | * Example: |
| 19 | * $schema = new CollectionSchema(); |
| 20 | * $schema->fields->set('FileName', $fieldDefDict); |
| 21 | */ |
| 22 | #[RequiresPdfVersion(PdfVersion::V1_7)] |
| 23 | class CollectionSchema extends PdfObject |
| 24 | { |
| 25 | public const PDF_TYPE = 'CollectionSchema'; |
| 26 | |
| 27 | public PdfDictionary $fields; |
| 28 | |
| 29 | public function __construct() |
| 30 | { |
| 31 | $this->fields = new PdfDictionary(); |
| 32 | } |
| 33 | |
| 34 | public function toPdf(): string |
| 35 | { |
| 36 | $dict = new PdfDictionary(); |
| 37 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 38 | |
| 39 | // Merge field entries from $this->fields into the dict |
| 40 | foreach ($this->fields->entries as $key => $value) { |
| 41 | $dict->set($key, $value); |
| 42 | } |
| 43 | |
| 44 | return $dict->toPdf(); |
| 45 | } |
| 46 | } |