Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PDF first page and convert it to JPG

Theres a way, using PHP exec and Image MagicK, to get the first PDF page and convert it to JPG?

like image 278
José Pablo Orozco Marín Avatar asked Feb 10 '11 17:02

José Pablo Orozco Marín


2 Answers

To answer your question, you convert just the nth page page as follows:

convert file.pdf[n] output_file.jpg

Note that this is zero based, so for the first page you would want to use file.pdf[0].

If you wish to convert the entire file, you can do:

convert file.pdf output_file.jpg

And this will produce a bunch of files in the form of output_file-0.jpg, output_file-1.jpg, ..., output_file-n.jpg

like image 173
mfonda Avatar answered Nov 06 '22 04:11

mfonda


There are many search results on SO already.

You have the choice between two duplicates:

  • ImageMagick/Imagick convert PDF to JPG using native PHP API using the PHP IM bindings

  • Imagemagick convert pdf to png using the command line.

Note that for this to work, you need Ghostscript installed along with ImageMagick. (I think this usually is the case.)

like image 4
Pekka Avatar answered Nov 06 '22 04:11

Pekka