1 | <?php |
||
11 | class Pdf |
||
12 | { |
||
13 | protected $pdfFile; |
||
14 | |||
15 | protected $resolution = 144; |
||
16 | |||
17 | protected $outputFormat = 'jpg'; |
||
18 | |||
19 | protected $page = 1; |
||
20 | |||
21 | protected $imagick; |
||
22 | |||
23 | protected $numberOfPages; |
||
24 | |||
25 | protected $validOutputFormats = ['jpg', 'jpeg', 'png']; |
||
26 | |||
27 | protected $layerMethod = Imagick::LAYERMETHOD_FLATTEN; |
||
28 | |||
29 | protected $colorspace; |
||
30 | |||
31 | protected $compressionQuality; |
||
32 | |||
33 | /** |
||
34 | * @param string $pdfFile The path or url to the pdffile. |
||
35 | * |
||
36 | * @throws \Spatie\PdfToImage\Exceptions\PdfDoesNotExist |
||
37 | */ |
||
38 | public function __construct($pdfFile) |
||
50 | |||
51 | /** |
||
52 | * Set the raster resolution. |
||
53 | * |
||
54 | * @param int $resolution |
||
55 | * |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function setResolution($resolution) |
||
64 | |||
65 | /** |
||
66 | * Set the output format. |
||
67 | * |
||
68 | * @param string $outputFormat |
||
69 | * |
||
70 | * @return $this |
||
71 | * |
||
72 | * @throws \Spatie\PdfToImage\Exceptions\InvalidFormat |
||
73 | */ |
||
74 | public function setOutputFormat($outputFormat) |
||
84 | |||
85 | /** |
||
86 | * Sets the layer method for Imagick::mergeImageLayers() |
||
87 | * If int, should correspond to a predefined LAYERMETHOD constant. |
||
88 | * If null, Imagick::mergeImageLayers() will not be called. |
||
89 | * |
||
90 | * @param int|null |
||
91 | * |
||
92 | * @return $this |
||
93 | * |
||
94 | * @throws \Spatie\PdfToImage\Exceptions\InvalidLayerMethod |
||
95 | * |
||
96 | * @see https://secure.php.net/manual/en/imagick.constants.php |
||
97 | * @see Pdf::getImageData() |
||
98 | */ |
||
99 | public function setLayerMethod($layerMethod) |
||
112 | |||
113 | /** |
||
114 | * Determine if the given format is a valid output format. |
||
115 | * |
||
116 | * @param $outputFormat |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function isValidOutputFormat($outputFormat) |
||
124 | |||
125 | /** |
||
126 | * Set the page number that should be rendered. |
||
127 | * |
||
128 | * @param int $page |
||
129 | * |
||
130 | * @return $this |
||
131 | * |
||
132 | * @throws \Spatie\PdfToImage\Exceptions\PageDoesNotExist |
||
133 | */ |
||
134 | public function setPage($page) |
||
144 | |||
145 | /** |
||
146 | * Get the number of pages in the pdf file. |
||
147 | * |
||
148 | * @return int |
||
149 | */ |
||
150 | public function getNumberOfPages() |
||
154 | |||
155 | /** |
||
156 | * Save the image to the given path. |
||
157 | * |
||
158 | * @param string $pathToImage |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function saveImage($pathToImage) |
||
168 | |||
169 | /** |
||
170 | * Save the file as images to the given directory. |
||
171 | * |
||
172 | * @param string $directory |
||
173 | * @param string $prefix |
||
174 | * |
||
175 | * @return array $files the paths to the created images |
||
176 | */ |
||
177 | public function saveAllPagesAsImages($directory, $prefix = '') |
||
195 | |||
196 | /** |
||
197 | * Return raw image data. |
||
198 | * |
||
199 | * @param string $pathToImage |
||
200 | * |
||
201 | * @return \Imagick |
||
202 | */ |
||
203 | public function getImageData($pathToImage) |
||
235 | |||
236 | /** |
||
237 | * @param int $colorspace |
||
238 | * |
||
239 | * @return $this |
||
240 | */ |
||
241 | public function setColorspace(int $colorspace) |
||
247 | |||
248 | /** |
||
249 | * @param int $compressionQuality |
||
250 | * |
||
251 | * @return $this |
||
252 | */ |
||
253 | public function setCompressionQuality(int $compressionQuality) |
||
259 | |||
260 | /** |
||
261 | * Return remote raw image data. |
||
262 | * |
||
263 | * @param string $pathToImage |
||
264 | * |
||
265 | * @return \Imagick |
||
266 | */ |
||
267 | protected function getRemoteImageData($pathToImage) |
||
281 | |||
282 | /** |
||
283 | * Determine in which format the image must be rendered. |
||
284 | * |
||
285 | * @param $pathToImage |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | protected function determineOutputFormat($pathToImage) |
||
305 | } |
||
306 |