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.
<?php $im = new imagick('file.pdf'); $im->setImageFormat('jpg'); header('Content-Type: image/jpeg'); echo $im; ?>
For those who don't have ImageMagick for whatever reason, GD functions will also work, in conjunction with GhostScript. Run the ghostscript command with
exec() to convert a PDF to JPG, and manipulate the resulting file with
Run the ghostscript command:
exec('gs -dSAFER -dBATCH -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r300 -sOutputFile=whatever.jpg input.pdf')
To manipulate, create a new placeholder image,
$newimage = imagecreatetruecolor(...), and bring in the current image.
$image = imagecreatefromjpeg('whatever.jpg'), and then you can use
imagecopyresampled() to change the size, or any number of other built-in, non-