PHP/WinServer PDF to JPG

1.2k Views Asked by At

Is there a plugin / extension that exists for PHP to convert PDF docs to a JPG format on a windows server 2000 machine?

3

There are 3 best solutions below

0
On BEST ANSWER

ImageMagick is probably the best choice. See e.g. this question: How to get PDF first page and convert it to JPG

Note that ImageMagick needs Ghostscript installed in order to process PDFs.

0
On

You can install ImageMagick and call it via system(). Here's the command to convert a PDF into it's individual pages (in JPEG):

convert foobar.pdf foobar.jpg

Once you make temporary images, you can just display them. I think that you can extract the first page using this command:

convert sample.pdf[0] sample.jpg
0
On

As pointed out by Pekka ImageMagick is able to do this via Ghostscript, there are other libraries that wrap Ghostscript and give you a little more control over the process. Andreas Heigl's PHP Ghostscript Wrapper is an example.

Depending on the PDF you are trying to convert you may discover that the colours become washed out, this is caused by the conversion between CMYK (or possibly CMYKA) and RGB. Depending on your needs you may need to convert to TIFF (that supports CMYK) then use another library with a better color space conversion algorithm.