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 | /** |
||
30 | * @param string $pdfFile The path or url to the pdffile. |
||
31 | * |
||
32 | * @throws \Spatie\PdfToImage\Exceptions\PdfDoesNotExist |
||
33 | */ |
||
34 | public function __construct($pdfFile) |
||
46 | |||
47 | /** |
||
48 | * Set the raster resolution. |
||
49 | * |
||
50 | * @param int $resolution |
||
51 | * |
||
52 | * @return $this |
||
53 | */ |
||
54 | public function setResolution($resolution) |
||
60 | |||
61 | /** |
||
62 | * Set the output format. |
||
63 | * |
||
64 | * @param string $outputFormat |
||
65 | * |
||
66 | * @return $this |
||
67 | * |
||
68 | * @throws \Spatie\PdfToImage\Exceptions\InvalidFormat |
||
69 | */ |
||
70 | public function setOutputFormat($outputFormat) |
||
80 | |||
81 | /** |
||
82 | * Sets the layer method for Imagick::mergeImageLayers() |
||
83 | * If int, should correspond to a predefined LAYERMETHOD constant. |
||
84 | * If null, Imagick::mergeImageLayers() will not be called. |
||
85 | * |
||
86 | * @param int|null |
||
87 | * |
||
88 | * @return $this |
||
89 | * |
||
90 | * @throws \Spatie\PdfToImage\Exceptions\InvalidLayerMethod |
||
91 | * |
||
92 | * @see https://secure.php.net/manual/en/imagick.constants.php |
||
93 | * @see Pdf::getImageData() |
||
94 | */ |
||
95 | public function setLayerMethod($layerMethod) |
||
108 | |||
109 | /** |
||
110 | * Determine if the given format is a valid output format. |
||
111 | * |
||
112 | * @param $outputFormat |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function isValidOutputFormat($outputFormat) |
||
120 | |||
121 | /** |
||
122 | * Set the page number that should be rendered. |
||
123 | * |
||
124 | * @param int $page |
||
125 | * |
||
126 | * @return $this |
||
127 | * |
||
128 | * @throws \Spatie\PdfToImage\Exceptions\PageDoesNotExist |
||
129 | */ |
||
130 | public function setPage($page) |
||
140 | |||
141 | /** |
||
142 | * Get the number of pages in the pdf file. |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | public function getNumberOfPages() |
||
150 | |||
151 | /** |
||
152 | * Save the image to the given path. |
||
153 | * |
||
154 | * @param string $pathToImage |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function saveImage($pathToImage) |
||
164 | |||
165 | /** |
||
166 | * Save the file as images to the given directory. |
||
167 | * |
||
168 | * @param string $directory |
||
169 | * @param string $prefix |
||
170 | * |
||
171 | * @return array $files the paths to the created images |
||
172 | */ |
||
173 | public function saveAllPagesAsImages($directory, $prefix = '') |
||
191 | |||
192 | /** |
||
193 | * Return raw image data. |
||
194 | * |
||
195 | * @param string $pathToImage |
||
196 | * |
||
197 | * @return \Imagick |
||
198 | */ |
||
199 | public function getImageData($pathToImage) |
||
223 | |||
224 | /** |
||
225 | * Return remote raw image data. |
||
226 | * |
||
227 | * @param string $pathToImage |
||
228 | * |
||
229 | * @return \Imagick |
||
230 | */ |
||
231 | protected function getRemoteImageData($pathToImage) |
||
245 | |||
246 | /** |
||
247 | * Determine in which format the image must be rendered. |
||
248 | * |
||
249 | * @param $pathToImage |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | protected function determineOutputFormat($pathToImage) |
||
269 | } |
||
270 |