views:

6039

answers:

3

Our environment is a LAMP stack.

I'm wondering what libraries/extensions etc. would be required to convert a portion of a PDF document into 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 displaying on a web page.

+22  A: 

You need ImageMagick and GhostScript

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat( "jpg" );
header( "Content-Type: image/jpeg" );
echo $im;
?>

The [0] means page 1.

Paolo Bergantino
yes, it works. You can also do: $im->setResolution( 300, 300 ) for example to render your pdf at desire resolution.
Luis Melgratti
+3  A: 

to add:

you can also get the page count using $im->getNumberImages();

then you can can create thumbs of all the pages using a loop, eg. 'file.pdf['.$x.']'

Jason
A: 

how images convert into pdf formate in php example

vikas