1 | <?php |
||
10 | class Pdf |
||
11 | { |
||
12 | protected $pdfFile; |
||
13 | |||
14 | protected $resolution = 144; |
||
15 | |||
16 | protected $outputFormat = 'jpg'; |
||
17 | |||
18 | protected $page = 1; |
||
19 | |||
20 | protected $imagick; |
||
21 | |||
22 | protected $validOutputFormats = ['jpg', 'jpeg', 'png']; |
||
23 | |||
24 | protected $layerMethod = \Imagick::LAYERMETHOD_FLATTEN; |
||
25 | |||
26 | /** |
||
27 | * @param string $pdfFile The path or url to the pdffile. |
||
28 | * |
||
29 | * @throws \Spatie\PdfToImage\Exceptions\PdfDoesNotExist |
||
30 | */ |
||
31 | public function __construct($pdfFile) |
||
40 | |||
41 | /** |
||
42 | * Set the raster resolution. |
||
43 | * |
||
44 | * @param int $resolution |
||
45 | * |
||
46 | * @return $this |
||
47 | */ |
||
48 | public function setResolution($resolution) |
||
54 | |||
55 | /** |
||
56 | * Set the output format. |
||
57 | * |
||
58 | * @param string $outputFormat |
||
59 | * |
||
60 | * @return $this |
||
61 | * |
||
62 | * @throws \Spatie\PdfToImage\Exceptions\InvalidFormat |
||
63 | */ |
||
64 | public function setOutputFormat($outputFormat) |
||
74 | |||
75 | /** |
||
76 | * Sets the layer method for \Imagicl::mergeImageLayers() |
||
77 | * If int, should correspond to a predefined LAYERMETHOD constant. |
||
78 | * If null, \Imagicl::mergeImageLayers() will not be called. |
||
79 | * |
||
80 | * @param int|null |
||
81 | * |
||
82 | * @return $this |
||
83 | * |
||
84 | * @throws \Spatie\PdfToImage\Exceptions\InvalidLayerMethod |
||
85 | * |
||
86 | * @see https://secure.php.net/manual/en/imagick.constants.php |
||
87 | * @see Pdf::getImageData() |
||
88 | */ |
||
89 | public function setLayerMethod($layerMethod) |
||
100 | |||
101 | /** |
||
102 | * Determine if the given format is a valid output format. |
||
103 | * |
||
104 | * @param $outputFormat |
||
105 | * |
||
106 | * @return bool |
||
107 | */ |
||
108 | public function isValidOutputFormat($outputFormat) |
||
112 | |||
113 | /** |
||
114 | * Set the page number that should be rendered. |
||
115 | * |
||
116 | * @param int $page |
||
117 | * |
||
118 | * @return $this |
||
119 | * |
||
120 | * @throws \Spatie\PdfToImage\Exceptions\PageDoesNotExist |
||
121 | */ |
||
122 | public function setPage($page) |
||
132 | |||
133 | /** |
||
134 | * Get the number of pages in the pdf file. |
||
135 | * |
||
136 | * @return int |
||
137 | */ |
||
138 | public function getNumberOfPages() |
||
142 | |||
143 | /** |
||
144 | * Save the image to the given path. |
||
145 | * |
||
146 | * @param string $pathToImage |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | public function saveImage($pathToImage) |
||
156 | |||
157 | /** |
||
158 | * Save the file as images to the given directory. |
||
159 | * |
||
160 | * @param string $directory |
||
161 | * @param string $prefix |
||
162 | * |
||
163 | * @return array $files the paths to the created images |
||
164 | */ |
||
165 | public function saveAllPagesAsImages($directory, $prefix = '') |
||
183 | |||
184 | /** |
||
185 | * Return raw image data. |
||
186 | * |
||
187 | * @param string $pathToImage |
||
188 | * |
||
189 | * @return \Imagick |
||
190 | */ |
||
191 | public function getImageData($pathToImage) |
||
205 | |||
206 | /** |
||
207 | * Determine in which format the image must be rendered. |
||
208 | * |
||
209 | * @param $pathToImage |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | protected function determineOutputFormat($pathToImage) |
||
229 | } |
||
230 |