TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. 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

Using the preview package to generate individual PDFs of images within your document has been covered, for example, in this thread. However, I am trying to understand how you can use Ghostscript to output each individual page. To review, the command I use is

\usepackage[active, pdftex, tightpage]{preview}

along with


In the linked discussion, it is proposed to use this command

gs -opics%2d.pdf -sDEVICE=pdfwrite file.pdf

However, there are two problems.

  1. The command does not seem to work. Only a single pdf file is generated and it has multiple pages.
  2. The generated file seems much smaller than the original file. I am somewhat worried by GS's compression. Is this something to be worried about for files that need to be print-ready? If so, how do you make it so GS outputs something with absolutely no compression over the original?
share|improve this question
up vote 2 down vote accepted

You can do this using pdftk:

pdftk foo.pdf burst output foo_p%03d.pdf

I don't think there's any issue of compression here in the sense of lossy compression. GS doesn't do anything like that. However, it's possible that it is not embedding fonts, or it's subsetting fonts. To check this, you can use pdffonts. It's also possible that whatever software you used to generate the original pdf was simply generating inefficient code.

share|improve this answer
gs will do lossy compression, depending on the options passed to it. In particular it may downsample images, or dct ("jpeg") compress them. – Lev Bishop Jul 25 '11 at 20:09
AFAIK there's no way to get gs to not resample jpegs but pass them through. – Martin Schröder Jul 25 '11 at 21:10
@Martin: you can tell gs to recode losslessly recode the DCT images with the Huffman/LZ77 Flate ("zip") encoding. -dColorImageFilter=/FlateEncode. This is lossless but makes the file larger. Indeed you can't tell it to pass DCT encoded images as unchanged DCT (not reencoded): Adobe Distiller knows a parameter PassThroughJPEGImages but gs does not respect this (see item 3.8 in the ghostscript projects page). – Lev Bishop Jul 25 '11 at 22:36

Q1: yes, the -ofilename%d.ext format does not work for pdfwrite or pswrite gs devices. You have to use -dFirstPage=n -dLastPage=n to pull out the n-th page. It's probably easier to use something like pdftk, though, as Ben suggested.

Q2: usually the files seem smaller simply because gs does a better job of generating efficient PDF. However, if there are bitmapped images it may do downsampling or lossy-encoding. The following options should avoid that:

-dPDFSETTINGS=/prepress  -dAutoRotatePages=/None
-dDownsampleColorImages=false -dDownsampleGrayImages=false -dDownsampleMonoImages=false
-dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode
-dAutoFilterGrayImages=false  -dGrayImageFilter=/FlateEncode
share|improve this answer

Your Answer


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.