Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| OCPropertiesDict | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
6 / 6 |
|
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\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfObject; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * PDF Optional Content Properties Dictionary (ISO 32000-2 Table 100). |
| 15 | * |
| 16 | * The /OCProperties entry in the Catalog. Contains all OCGs and |
| 17 | * the default viewing configuration. |
| 18 | * |
| 19 | * Example: |
| 20 | * $ocProps = new OCPropertiesDict($ocgsArray, $defaultConfig); |
| 21 | * $writer->register($ocProps); |
| 22 | * $catalog->ocProperties = new PdfReference($ocProps->objectNumber); |
| 23 | */ |
| 24 | #[RequiresPdfVersion(PdfVersion::V1_5)] |
| 25 | class OCPropertiesDict extends PdfObject |
| 26 | { |
| 27 | public PdfArray $ocgs; // /OCGs - required, all OCG refs |
| 28 | public PdfDictionary $d; // /D - required, default viewing config |
| 29 | public ?PdfArray $configs = null; // /Configs - optional alternate configs |
| 30 | |
| 31 | public function __construct(PdfArray $ocgs, PdfDictionary $defaultConfig) |
| 32 | { |
| 33 | $this->ocgs = $ocgs; |
| 34 | $this->d = $defaultConfig; |
| 35 | } |
| 36 | |
| 37 | public function toPdf(): string |
| 38 | { |
| 39 | $dict = new PdfDictionary(); |
| 40 | $dict->set('OCGs', $this->ocgs); |
| 41 | $dict->set('D', $this->d); |
| 42 | |
| 43 | if ($this->configs !== null) { |
| 44 | $dict->set('Configs', $this->configs); |
| 45 | } |
| 46 | |
| 47 | return $dict->toPdf(); |
| 48 | } |
| 49 | } |