Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
PageLabel
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 toPdf
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
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\PdfNumber;
10use Phpdftk\Pdf\Core\PdfObject;
11use Phpdftk\Pdf\Core\PdfString;
12use Phpdftk\Pdf\Core\PdfVersion;
13use Phpdftk\Pdf\Core\RequiresPdfVersion;
14
15/**
16 * PDF Page Label dictionary (/Type /PageLabel).
17 *
18 * Defines the numbering scheme for a range of pages.
19 * Page label ranges are stored as a number tree in /PageLabels in the Catalog;
20 * each key is the zero-based page index where the range begins.
21 *
22 * Numbering styles (/S):
23 *   D  - Decimal Arabic numerals (1, 2, 3, …)
24 *   r  - Lowercase Roman numerals (i, ii, iii, …)
25 *   R  - Uppercase Roman numerals (I, II, III, …)
26 *   a  - Lowercase letters (a, b, …, z, aa, …)
27 *   A  - Uppercase letters (A, B, …, Z, AA, …)
28 *   (omit /S to use prefix only, with no numeric part)
29 */
30#[RequiresPdfVersion(PdfVersion::V1_3)]
31class PageLabel extends PdfObject
32{
33    public const PDF_TYPE = 'PageLabel';
34
35    public ?PdfName $s   = null;  // /S  - numbering style
36    public ?PdfString $p = null;  // /P  - label prefix
37    public int $st       = 1;     // /St - starting value (default 1)
38
39    public function toPdf(): string
40    {
41        $dict = new PdfDictionary();
42        $dict->set('Type', new PdfName(self::PDF_TYPE));
43
44        if ($this->s !== null) {
45            $dict->set('S', $this->s);
46        }
47        if ($this->p !== null) {
48            $dict->set('P', $this->p);
49        }
50        if ($this->st !== 1) {
51            $dict->set('St', new PdfNumber($this->st));
52        }
53
54        return $dict->toPdf();
55    }
56}