Sometimes, for strange reasons, you can have the need to convert a pdf file into an image or into a collection of images.

I've tried a lot of methods to do this job, I used: inkskape, gimp, libreoffice……. to import a save, 

They can do this simple job, but they are not designed for this specific job.

If you have a  pdf file, long one page,  you can use the above programs and you will win the match, but if you have to do something complex you will loose the game.

For example imagine you have to convert in png format a pdf file containing 50 pages and you want to use inkscape to convert it. You ave to 

  1. Open the file.pdf with inkscape
  2. Select the page you want to convert
  3. Select all the elements of the pages
  4. Export the selection as png file
  5. Give it a name.
  6. Go to step 1 for the next page.

This is a long and tedious work, but the shell can help you.

If you are on a UNIX system (but this works also on cygwin) you have to install the imagemagick packet.


imagemagick


The from the shell you have to issue a command like the following one:

$ convert file.pdf pageNo%d.png 

this enough for a first attempt. You can also change the output format changing the extensions of the second argument, for example if you issue:

 

$ convert file.pdf pageNo%d.jpg 

you will obtain a set of jpeg images.
Since pictures can be compressed, you can set the compression ratio, to not compress use the following

 

$ convert -quality 100 file.pdf pageNo%d.jpg 

If you want to setup the horizontal and vertical density of the output pictures you can use the "-density" option. For example to generate a 144×144 dpi picture you can issue the following command:

 

$ convert -quality 100 -density 144x144 file.pdf pageNo%d.jpg 

With imagemagick you have a lot of option to set, read the manpage to continue….

Gg1