Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 have requirement of converting PDF pages to images. There is a background image with some text written, so when I save this as image only background image got saved.

Is there any software available for the same so that complete page can be converted to image?

share|improve this question

10 Answers 10

up vote 91 down vote accepted
  1. Install imagemagick

  2. Using a terminal where the pdf is located:

    convert -density 150 input.pdf -quality 90 output.png


    • PNG, JPG or (virtually) any other image format can be chosen
    • -density xxx will set the dpi to xxx (common are 150 and 300)
    • -quality xxx will set the compression to xxx for PNG, JPG and MIFF file formates (100 means no compression)
    • all other options (such as trimming, grayscale, etc) can be viewed on the website of Image Magic.
share|improve this answer
The answer as is does work but the resolution is very poor. Therefore not currently an answer that is useful. Maybe if convert has some parameters that can be specified this could change. – Elijah Lynn Jan 16 '15 at 19:57
This answer is much higher quality – Elijah Lynn Jan 16 '15 at 20:06
You can change the density by adding the -density 300 parameter – OHLÁLÁ Apr 1 '15 at 12:18
The image in your answer is broken. Perhaps you should update it. – Petr R. Oct 2 '15 at 8:44

In the poppler-utils packages there is the utility pdftoppm capable of converting pages from a pdf file to ppm, png or jpeg format:

pdftoppm -png file.pdf prefix

will produce prefix-01.png etc. for each page. By default the resolution is 150dpi. Increase the resolution (for higher quality output) as follows:

pdftoppm -rx 300 -ry 300 -png file.pdf prefix

To print only one page, use

pdftoppm -f N -singlefile -png file.pdf prefix

where N is the page number, beginning with 1.

share|improve this answer
Thank you so much. Much better quality than with imagemagick or graphicsmagick! – dAnjou Jan 9 '13 at 0:18
pdftoppm is much faster than convert – zuo Nov 6 '13 at 4:52
This is so great! +1 – Ionică Bizău Jun 6 '14 at 11:38
Can't belive how easy it was! And the package is already installed by default! Loved it. THANKS! – Rosamunda May 11 '15 at 18:04
This is really much better than imagemagick. Imagemagick actually changed the colors in an unexpected way in my case! – Dominik Sep 17 '15 at 7:16

IIRC GIMP is capable of using PDFs, i.e. converting them into images. So if you want to edit the images right away - GIMP is your friend.

share|improve this answer

You can use convert and specify a higher density using -density option.

eg. convert -d 300 foo.pdf bar.png

share|improve this answer
can you explain more about what is density and what It can do? – Raja Jul 24 '14 at 4:03
@AgentCool It specifies the horizontal and vertical image density (in ppi). – Arjun Jul 27 '14 at 10:02

To get a single page from gm convert, add [N] (with N the page number starting at 0) to the PDF name, ie gm convert foo.pdf[11] out.png to get the 12th page from the PDF.

For pdftoppm use -f N -singlefile, where N is the page number starting at 1, ie pdftoppm -f 12 -singlefile foo.pdf out for the same result. It appears to always add ".png" to the output filename and there is no way to stop this.

share|improve this answer

The currently accepted answer does the job but results in an output which is larger in size and suffers from quality loss.

The method in the answer given here results in an output which is comparable in size to the input and doesn't suffer from quality loss.

TLDR - Use pdfimages : pdfimages -j input.pdf output

Quoting the linked answer:

It's not clear what you mean by "quality loss". That could mean a lot of different things. Could you post some samples to illustrate? Perhaps cut the same section out of the poor quality and good quality versions (as a PNG to avoid further quality loss).

Perhaps you need to use -density to do the conversion at a higher dpi:

convert -density 300 file.pdf page_%04d.jpg

(You can prepend -units PixelsPerInch or -units PixelsPerCentimeter if necessary. My copy defaults to ppi.)

Update: As you pointed out, gscan2pdf (the way you're using it) is just a wrapper for pdfimages (from poppler). pdfimages does not do the same thing that convert does when given a PDF as input.

convert takes the PDF, renders it at some resolution, and uses the resulting bitmap as the source image.

pdfimages looks through the PDF for embedded bitmap images and exports each one to a file. It simply ignores any text or vector drawing commands in the PDF.

As a result, if what you have is a PDF that's just a wrapper around a series of bitmaps, pdfimages will do a much better job of extracting them, because it gets you the raw data at its original size. You probably also want to use the -j option to pdfimages, because a PDF can contain raw JPEG data. By default, pdfimages converts everything to PNM format, and converting JPEG > PPM > JPEG is a lossy process.

So, try

pdfimages -j file.pdf page

You may or may not need to follow that with a convert to .jpg step (depending on what bitmap format the PDF was using).

I tried this command on a PDF that I had made myself from a sequence of JPEG images. The extracted JPEGs were byte-for-byte identical to the source images. You can't get higher quality than that.

share|improve this answer

Master PDF Editor (ver 2.2) has this option buit in. Open the PDF file and then go to File> Export to> Images. It presents a dialog where you can define different options for the output. Extremely useful. Hope this info helps.

share|improve this answer

If your pdfs are scanned, the images are already stored as part of pdf. you will simply need to extract them with pdfimages:

pdfimages my-file.pdf prefix 
share|improve this answer
This is the perfect solution for scanned pdfs, as with this you can, with one command, extract the original jpgs, and without further recompressions. – Jose Gómez Jan 31 at 22:49

If you only want to convert a specific page of a PDF to a PNG, you can pipe pdftk to convert (described above) like this:

pdftk document.pdf cat 12 output - | convert - document-page-12.png
share|improve this answer

PDF Mod also allows exporting images of all or individual pages of PDF files.

  • Open PDF file in PDF Mod
  • Select page(s)-
  • Edit > Export image(s)
share|improve this answer

protected by Community Apr 18 '15 at 0:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.