Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I convert a pdf file to bunch of jpg files using

convert -quality 100 file.pdf page_%04d.jpg

I have appreciable quality loss.

However if I do the following, there is no (noticeable) quality loss:

Start gscan2pdf, choose file-> import (and choose file.pdf). Then go to the temporary directory of gscan2pdf. There are many pnm files (one for every page of the pdf-file). Now I do

  for file in *.pnm; do            
  convert $file $file.jpg done

The resulting jpg-files are (roughly) of the same quality as the original pdf (which is what I want).

Now my question is, if there is a simple command line way to convert the pdf file to a bunch of jpg files without noticeable quality loss? (The solution above is too complicated and time consuming).

share|improve this question
    
What is not clear in your questions is whether you talk about text and vector graphics in your pdf, or whether you mean to extract embedded images. –  asoundmove Apr 23 '11 at 4:02
add comment

4 Answers

up vote 12 down vote accepted

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
    
+1 I am so glad I didn't submit to the snobbery misreading one of your sentences inspired in me and actually tried pdfimages -- probably the most useful program I have used in months! I'd encourage everyone to try it! –  ixtmixilix Apr 22 '12 at 15:45
    
@ixtmixilix, I'm curious. What did you misread, and how? –  cjm Apr 22 '12 at 15:57
    
Pretty awesome! Solved my day. Thank you! –  Geppettvs D'Constanzo Sep 5 '12 at 22:45
add comment

Looking at the gscan2pdf source code I noticed that it uses pdfimages. So pdfimages file.pdf page would result in page-001.ppm, page-002.ppm etc.

share|improve this answer
add comment

What is not clear in your question is whether you talk about text and vector graphics in your pdf, or whether your pdf contains embedded images.

Having read what gscan2pdf is about, my guess is that your pdf files contain (only) embedded graphics.

convert essentially "prints" your pdf without regards for what the contents is. Like @cjm suggests, you might want to change the print density. This is the only way to increase quality for vector graphics.

If instead, what you want to do is extract embedded images (much like gscan2pdf seems to do), guessing the density will usually lead to either quality loss or higher quality than required (and waste of disk space). The answer then is to extract the image rather than print the pdf. See this article which basically advocates the use of pdfimages in order to extract images without quality loss.

share|improve this answer
add comment

the response from @cjm is correct, but if you like GUI and don't want to render all pdf pages, just to get some image, use gimp.

Open a pdf with gimp an you will get a import window with all pages rendered. Choose whatever pages you want and set resolution to 600 pix/inch (I found 300 too much sharpen in many cases). Save to format you want with "File/export"

Anyway, there must be a flag to select desired pages from command line.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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