Convert a PDF to an image
mainTo convert a PDF to an image, instantiate the Spatie\PdfToImage\Pdf class with the path to your PDF, then call the save() method with the desired output path.
Note on formats:
- If the filename passed to
save()has extensions likejpg,jpeg,png, orwebp, the image will be saved in that format. - If no extension is provided, the output format defaults to
jpg.
Return values:
- If saving a single page: returns a
stringcontaining the path to the saved image. - If saving multiple pages: returns an
arrayof filenames.
$pdf = new \Spatie\PdfToImage\Pdf($pathToPdf);
$pdf->save($pathToWhereImageShouldBeStored);