Mathew Byrne Mathew Byrne - 29 days ago 24
PHP Question

How do I convert a PDF document to a preview image in PHP?

What libraries, extensions etc. would be required to render a portion of a PDF document to an image file?

Most PHP PDF libraries that I have found center around creating PDF documents, but is there a simple way to render a document to an image format suitable for web use?

Our environment is a LAMP stack.

Answer Source

You need ImageMagick and GhostScript

$im = new imagick('file.pdf[0]');
header('Content-Type: image/jpeg');
echo $im;

The [0] means page 1.