Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
30 / 30 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
| PdfAProfile | |
100.00% |
30 / 30 |
|
100.00% |
11 / 11 |
27 | |
100.00% |
1 / 1 |
| getFamily | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLevel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPart | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
| getConformanceLevel | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
7 | |||
| getPdfVersion | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
| getXmpNamespace | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getXmpPrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getXmpProperties | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| requiresTaggedStructure | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| prohibitsTransparency | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| allowsEmbeddedFiles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Conformance\Profile; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfVersion; |
| 8 | |
| 9 | /** |
| 10 | * PDF/A conformance profiles (ISO 19005). |
| 11 | * |
| 12 | * PDF/A-1 (ISO 19005-1): based on PDF 1.4 |
| 13 | * PDF/A-2 (ISO 19005-2): based on PDF 1.7 |
| 14 | * PDF/A-3 (ISO 19005-3): based on PDF 1.7, allows embedded files |
| 15 | * PDF/A-4 (ISO 19005-4): based on PDF 2.0 |
| 16 | */ |
| 17 | enum PdfAProfile: string implements ConformanceProfile |
| 18 | { |
| 19 | case A1a = '1a'; |
| 20 | case A1b = '1b'; |
| 21 | case A2a = '2a'; |
| 22 | case A2b = '2b'; |
| 23 | case A2u = '2u'; |
| 24 | case A3a = '3a'; |
| 25 | case A3b = '3b'; |
| 26 | case A3u = '3u'; |
| 27 | case A4 = '4'; |
| 28 | case A4e = '4e'; |
| 29 | case A4f = '4f'; |
| 30 | |
| 31 | public function getFamily(): string |
| 32 | { |
| 33 | return 'PDF/A'; |
| 34 | } |
| 35 | |
| 36 | public function getLevel(): string |
| 37 | { |
| 38 | return $this->value; |
| 39 | } |
| 40 | |
| 41 | /** ISO 19005 part number (1, 2, 3, or 4). */ |
| 42 | public function getPart(): int |
| 43 | { |
| 44 | return match ($this) { |
| 45 | self::A1a, self::A1b => 1, |
| 46 | self::A2a, self::A2b, self::A2u => 2, |
| 47 | self::A3a, self::A3b, self::A3u => 3, |
| 48 | self::A4, self::A4e, self::A4f => 4, |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | /** Conformance level letter (a, b, u, e, f) or null for PDF/A-4 base. */ |
| 53 | public function getConformanceLevel(): ?string |
| 54 | { |
| 55 | return match ($this) { |
| 56 | self::A1a, self::A2a, self::A3a => 'A', |
| 57 | self::A1b, self::A2b, self::A3b => 'B', |
| 58 | self::A2u, self::A3u => 'U', |
| 59 | self::A4e => 'E', |
| 60 | self::A4f => 'F', |
| 61 | self::A4 => null, |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | public function getPdfVersion(): PdfVersion |
| 66 | { |
| 67 | return match ($this->getPart()) { |
| 68 | 1 => PdfVersion::V1_4, |
| 69 | 2, 3 => PdfVersion::V1_7, |
| 70 | 4 => PdfVersion::V2_0, |
| 71 | }; |
| 72 | } |
| 73 | |
| 74 | public function getXmpNamespace(): string |
| 75 | { |
| 76 | return 'http://www.aiim.org/pdfa/ns/id/'; |
| 77 | } |
| 78 | |
| 79 | public function getXmpPrefix(): string |
| 80 | { |
| 81 | return 'pdfaid'; |
| 82 | } |
| 83 | |
| 84 | public function getXmpProperties(): array |
| 85 | { |
| 86 | $props = ['part' => (string) $this->getPart()]; |
| 87 | $level = $this->getConformanceLevel(); |
| 88 | if ($level !== null) { |
| 89 | $props['conformance'] = $level; |
| 90 | } |
| 91 | return $props; |
| 92 | } |
| 93 | |
| 94 | /** Whether this profile requires Level A (tagged PDF). */ |
| 95 | public function requiresTaggedStructure(): bool |
| 96 | { |
| 97 | return match ($this) { |
| 98 | self::A1a, self::A2a, self::A3a => true, |
| 99 | default => false, |
| 100 | }; |
| 101 | } |
| 102 | |
| 103 | /** Whether this profile prohibits transparency (PDF/A-1 only). */ |
| 104 | public function prohibitsTransparency(): bool |
| 105 | { |
| 106 | return $this->getPart() === 1; |
| 107 | } |
| 108 | |
| 109 | /** Whether this profile allows embedded files (PDF/A-3+ only). */ |
| 110 | public function allowsEmbeddedFiles(): bool |
| 111 | { |
| 112 | return $this->getPart() >= 3; |
| 113 | } |
| 114 | } |