Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've a PDF composed by N pages. I want to convert this PDF in N jpeg images (by command line, no Php, Java or other programming languages).

I'm trying to do this with GHOSTSCRIPT but the output which GS get to me is never like the output i'm looking for.


gs \
  -sDEVICE=jpeg \
  -r300 \
  -g800x600 \
  -dPDFFitPage \
  -sOutputFile=output/%d.jpg \

produce N jpeg images with 800x600 resolution but it seems that the PDF page is cropped and not fit.

How can i symply get N jpeg images from an N-Pages PDF (from command line.) ?

share|improve this question
up vote 2 down vote accepted

The commandline alesdario used does the following:

  1. Tell Ghostscript to use output dimension of 800px by 600px (pixels).
  2. Tell Ghostscript to use a resolution of 300dpi (dots per inch).
  3. Tell Ghostscript to use an output dimension of 72 device points.

All three cannot work at the same time, because if two go together they will contradict the third.

At 300dpi a canvas of 800x600 will result in a physical dimension of 2.33in x 2in (inches) -- much less than your original PDF page size (likely) was.

To 'simply get N jpeg images from an N-Pages PDF (from command line)' use this command:

 gs \
   -sDEVICE=jpeg \
   -o output/%d.jpg \

This is the most simple call, will not crop anything and will use Ghostscript's default settings for:

  • image resolution: this is 72 dpi for JPEG output
  • dimension of the output images: this follows respective PDF page size (however, Ghostscript assumes PDF to use 720dpi).

In order to get N JPEG images from a N-page PDF at a pre-defined resolution and a pre-defined image dimension, you need to do some computing yourself and set the -r and -g values accordingly. For example, you may want 200 dpi for your JPEG (from PDF page sizes that were ISO A4 [595x842 pt]): that means you need to add -r200 -g1652x2338 to the commandline if you want to avoid cropping.... This will make Ghostscript resample all pages and the objects contained there to the new resolution.

share|improve this answer

Try ImageMagick. The command you want I believe is:

$ convert -density 400 my.pdf my.jpeg
share|improve this answer
ImageMagick is a beautiful tool, but it doesn't do the work of PDF->JPEG conversion by itself. It uses Ghostscript as a delegate. So if you need a high level of control over your results, you're better off using Ghostscript directly. Your commandline above is much easier to use and faster to type, though, than a full Ghostscript commandline. – Kurt Pfeifle Apr 27 '12 at 16:21
So, how can i obtain a normal JPEG image from a PDF ? I don't need for particoular configurations. I need something like a simple (for example) split mypdf.pdf --> myimg.jpeg . I'm not interested about how the tool does the conversion. I'm interested only about the result. – alesdario Apr 27 '12 at 16:29
You cannot be simply 'interested in the result' without defining what kind of result you are interested in... A specific resolution as defined by -r300? A specific image size as defined by -g800x600 (which in turn implies a resolution)? A specific image size as defined by -dDEVICEWIDTHPOINTS=... (which, also, implies a resolution)? -- Or maybe you want 'simply the default result' Ghostscript gives you? Then see my full answer. – Kurt Pfeifle Apr 27 '12 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .