Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
PdfObject
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 toPdf
n/a
0 / 0
n/a
0 / 0
0
 toIndirectObject
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core;
6
7/**
8 * Base class for PDF objects that live as indirect objects (`X Y obj ... endobj`).
9 *
10 * Every PdfObject gets an object number assigned by {@see File\ObjectRegistry}
11 * when registered with a writer. Unlike plain {@see Serializable} types
12 * (which serialize inline), PdfObjects can be referenced from anywhere in
13 * the document via {@see PdfReference}.
14 */
15abstract class PdfObject implements Serializable
16{
17    public int $objectNumber = 0;
18    public int $generationNumber = 0;
19
20    /**
21     * Serialize the object's dictionary/value to PDF syntax.
22     */
23    abstract public function toPdf(): string;
24
25    /**
26     * Wrap the object in an indirect object structure:
27     *   X Y obj
28     *   ...
29     *   endobj
30     */
31    public function toIndirectObject(): string
32    {
33        return sprintf(
34            "%d %d obj\n%s\nendobj",
35            $this->objectNumber,
36            $this->generationNumber,
37            $this->toPdf(),
38        );
39    }
40}