1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Ghostscript package |
4
|
|
|
* |
5
|
|
|
* @author Daniel Schröder <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GravityMedia\Ghostscript\Devices; |
9
|
|
|
|
10
|
|
|
use GravityMedia\Ghostscript\Enum\PdfSettings; |
11
|
|
|
use GravityMedia\Ghostscript\Process\Arguments as ProcessArguments; |
12
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The PDF write device class |
16
|
|
|
* |
17
|
|
|
* @package GravityMedia\Ghostscript\Devices |
18
|
|
|
*/ |
19
|
|
|
class PdfWrite extends AbstractDevice |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Use distiller parameters |
23
|
|
|
*/ |
24
|
|
|
use DistillerParametersTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Use color image compression distiller parameters |
28
|
|
|
*/ |
29
|
|
|
use DistillerParameters\ColorImageCompressionTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Use grayscale image compression distiller parameters |
33
|
|
|
*/ |
34
|
|
|
use DistillerParameters\GrayscaleImageCompressionTrait; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Use monochrome image compression distiller parameters |
38
|
|
|
*/ |
39
|
|
|
use DistillerParameters\MonochromeImageCompressionTrait; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Use page compression distiller parameters |
43
|
|
|
*/ |
44
|
|
|
use DistillerParameters\PageCompressionTrait; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Use font distiller parameters |
48
|
|
|
*/ |
49
|
|
|
use DistillerParameters\FontTrait; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Use color conversion distiller parameters |
53
|
|
|
*/ |
54
|
|
|
use DistillerParameters\ColorConversionTrait; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Use advanced distiller parameters |
58
|
|
|
*/ |
59
|
|
|
use DistillerParameters\AdvancedTrait; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The default compatibility level |
63
|
|
|
*/ |
64
|
|
|
const DEFAULT_COMPATIBILITY_LEVEL = 1.4; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Create PDF write device object |
68
|
|
|
* |
69
|
|
|
* @param ProcessBuilder $builder |
70
|
|
|
* @param ProcessArguments $arguments |
71
|
|
|
*/ |
72
|
24 |
|
public function __construct(ProcessBuilder $builder, ProcessArguments $arguments) |
73
|
|
|
{ |
74
|
24 |
|
parent::__construct($builder, $arguments->setArgument('-sDEVICE=pdfwrite')); |
75
|
|
|
|
76
|
24 |
|
$this->setCompatibilityLevel(self::DEFAULT_COMPATIBILITY_LEVEL); |
77
|
24 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get output file |
81
|
|
|
* |
82
|
|
|
* @return null|string |
83
|
|
|
*/ |
84
|
3 |
|
public function getOutputFile() |
85
|
|
|
{ |
86
|
3 |
|
return $this->getArgumentValue('-sOutputFile'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set output file |
91
|
|
|
* |
92
|
|
|
* @param string $outputFile |
93
|
|
|
* |
94
|
|
|
* @return $this |
95
|
|
|
*/ |
96
|
3 |
|
public function setOutputFile($outputFile) |
97
|
|
|
{ |
98
|
3 |
|
$this->setArgument('-sOutputFile=' . $outputFile); |
99
|
|
|
|
100
|
3 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get PDF settings |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
15 |
|
public function getPdfSettings() |
109
|
|
|
{ |
110
|
15 |
|
$value = $this->getArgumentValue('-dPDFSETTINGS'); |
111
|
15 |
|
if (null === $value) { |
112
|
15 |
|
return PdfSettings::__DEFAULT; |
113
|
|
|
} |
114
|
|
|
|
115
|
15 |
|
return substr($value, 1); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Set PDF settings |
120
|
|
|
* |
121
|
|
|
* @param string $pdfSettings |
122
|
|
|
* |
123
|
|
|
* @throws \InvalidArgumentException |
124
|
|
|
* |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
18 |
|
public function setPdfSettings($pdfSettings) |
128
|
|
|
{ |
129
|
18 |
|
$pdfSettings = ltrim($pdfSettings, '/'); |
130
|
18 |
|
if (!in_array($pdfSettings, PdfSettings::values())) { |
131
|
3 |
|
throw new \InvalidArgumentException('Invalid PDF settings argument'); |
132
|
|
|
} |
133
|
|
|
|
134
|
15 |
|
$this->setArgument(sprintf('-dPDFSETTINGS=/%s', $pdfSettings)); |
135
|
|
|
|
136
|
15 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|