|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BaconPdf |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/Bacon/BaconPdf For the canonical source repository |
|
6
|
|
|
* @copyright 2015 Ben Scholzen (DASPRiD) |
|
7
|
|
|
* @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Bacon\Pdf\Options; |
|
11
|
|
|
|
|
12
|
|
|
use Bacon\Pdf\Encryption\AbstractEncryption; |
|
13
|
|
|
use Bacon\Pdf\Encryption\EncryptionInterface; |
|
14
|
|
|
use Bacon\Pdf\Encryption\NullEncryption; |
|
15
|
|
|
use Bacon\Pdf\Exception\DomainException; |
|
16
|
|
|
|
|
17
|
|
|
final class PdfWriterOptions |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $pdfVersion; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var EncryptionOptions|null |
|
26
|
|
|
*/ |
|
27
|
|
|
private $encryptionOptions; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param string $pdfVersion |
|
31
|
|
|
* @throws DomainException |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($pdfVersion = '1.7') |
|
34
|
|
|
{ |
|
35
|
|
|
if (!in_array($pdfVersion, ['1.3', '1.4', '1.5', '1.6', '1.7'])) { |
|
36
|
|
|
throw new DomainException('PDF version is not in the supported range (1.3 - 1.7)'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$this->pdfVersion = $pdfVersion; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the PDF version to use for the document. |
|
44
|
|
|
* |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getPdfVersion() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->pdfVersion; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Sets encryption options. |
|
54
|
|
|
* |
|
55
|
|
|
* @param EncryptionOptions $encryptionOptions |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setEncryptionOptions(EncryptionOptions $encryptionOptions) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->encryptionOptions = $encryptionOptions; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $permanentFileIdentifier |
|
64
|
|
|
* @return EncryptionInterface |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getEncryption($permanentFileIdentifier) |
|
67
|
|
|
{ |
|
68
|
|
|
if (null === $this->encryptionOptions) { |
|
69
|
|
|
return new NullEncryption(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return AbstractEncryption::forPdfVersion($this->pdfVersion, $permanentFileIdentifier, $this->encryptionOptions); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|