My PDF concatenation page is quite popular, and I recently had occasion (while publishing a book through Lulu) to need a couple of other hard-to-find Postscript and PDF-related techniques, so I'm recording them here in case they're useful to others.

Disabling lossy compression in epstopdf

If you attempt to convert a raster image into a PDF (for instance, to use as a book cover) using pnmtops followed by epstopdf, you will find that it gets compressed with "DCTEncode", which is basically the same thing as JPEG. That's a lossy compression scheme, and it produces artifacts that look like JPEG artifacts, especially annoying if your image contains sharp-edged text.  These kinds of artifacts would be prohibitive if, for instance, you were trying to make a bar code label for a Lulu book.  Other free PDF-producing software (for instant, ps2pdf) is likely to have the same problem because they almost all use Ghostscript for the PDF-generating back end.

You can set the compression using poorly documented Ghostscript options.  The ones that work for me are "-dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode".  With epstopdf, there's no way I could find to specify those on the command line, so I set the GS_OPTIONS environment variable to contain that value.  Another possibility would be to use "/LZWEncode" instead of "/FlateEncode"; both are lossless, LZW may give better compression, but there were formerly patent issues with LZW. The patents on it are expired now, but many installations of Ghostscript date from before the expiry of the patents and will either fail, substitute Flate, or do no compression if LZW is requested.  "Flate" has problems too:  it is a Level 3 Postscript feature and may harm compatibility if you use it in Postscript as opposed to PDF, but as far as I can tell, support for it is required in PDF so you shouldn't have a problem using it for the purpose I'm suggesting.  Note:  the posting at the bottom of this page on the Lulu support Web BBS seems to indicate that Flate may be preferable to LZW for files submitted to them.

Rendering Postscript to a raster image

This command renders the Postscript file input.ps into a PPM image with a resolution of 600dpi, which it spits out on standard output for you to pipe into other software.  You want "ppmraw" instead of "ppm" because "ppm" is the ASCII version of the PPM format, and elephantine in size.  The "< /dev/null" is needed to prevent Ghostscript from prompting you for interactive commands; there may be a more elegant way to do that.  Changing the resolution, of course, just means changing the "-r600" option to whatever resolution you want.  This command runs without anti-aliasing.  I'm still looking for a way to turn on anti-aliasing in Ghostscript.  For the moment, I'm faking it by rendering at a higher resolution than I want and then scaling down.

gs -sDEVICE=ppmraw -q -sOutputFile=- -r600 input.ps < /dev/null

I want to REALLY embed the fonts, dammit!

To put all fonts in your PDF in as compatible a form as possible, use the options "-dSubsetFonts=false -dEmbedAllFonts=true" (with ps2pdf or any other Ghostscript-based PDF generator).  Be warned that that will include the entirety of every font you use, in the document, in a form that allows whoever gets the document to use the font.  That is, of course, the point; but it has implications for, and may be prohibited by, the copyright licensing on many fonts.

Related pages:

Comments

No comments yet.

New comments are disabled, pending transition to new site code.
Copyright 2017 Matthew Skala
Updates to this site: [RSS syndication file]