Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MetadataStream
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Document;
6
7use Phpdftk\Pdf\Core\PdfDictionary;
8use Phpdftk\Pdf\Core\PdfName;
9use Phpdftk\Pdf\Core\PdfStream;
10use Phpdftk\Pdf\Core\PdfVersion;
11use Phpdftk\Pdf\Core\RequiresPdfVersion;
12
13/**
14 * XMP metadata stream (/Type /Metadata /Subtype /XML) —
15 * ISO 32000-2 §14.3.2, Table 339.
16 *
17 * Thin typed wrapper around a `PdfStream` that sets the two required
18 * header entries. Use `packages/xmp` to generate the packet bytes and
19 * pass them here; assign the resulting indirect reference to
20 * `Catalog::$metadata`, `Page::$metadata`, etc.
21 */
22#[RequiresPdfVersion(PdfVersion::V1_4)]
23class MetadataStream extends PdfStream
24{
25    public const PDF_TYPE = 'Metadata';
26    public const PDF_SUBTYPE = 'XML';
27
28    public function __construct(string $xmpPacket = '')
29    {
30        parent::__construct(new PdfDictionary(), $xmpPacket);
31    }
32
33    public function toPdf(): string
34    {
35        $this->dictionary->set('Type', new PdfName(self::PDF_TYPE));
36        $this->dictionary->set('Subtype', new PdfName(self::PDF_SUBTYPE));
37        return parent::toPdf();
38    }
39}