Maintaining the BoundingBox in ps2pdf
March 2, 2012 at 10:46 AM by Dr. Drang
I have a bunch of Encapsulated PostScript (EPS) graphics that I’ve accumulated over the years—logos, letterheads, and other little image/text combinations that I use for company documents. Most of these were written directly in PostScript and have a BoundingBox
set in the document header, like this:
%!PS-Adobe-3.0 EPSF-3.0
%%Title: Letterhead
%%BoundingBox: 0 0 534 72
%%DocumentFonts: AvantGarde-Book
%%DocumentNeededFonts: AvantGarde-Book
%%EndComments
PostScript assumes, by default, that the image will be placed on a letter-sized page. The BoundingBox
parameter tells PostScript to crop the image to the given rectangle. In the example, the rectangle has a lower left corner at (0, 0) and an upper right corner at (534, 72). The coordinates are given in points.1
After switching from Linux to OS X in 2005, I converted most of these EPS files to PDF because the Mac is more PDF-centric. I don’t really remember how I did it, but the easiest tool to use is ps2pdf, a script that comes with, and relies on, Ghostscript, the open-source PostScript workalike developed at the University of Wisconsin.
Today I needed to convert a couple of those old EPSes that I had somehow skipped over back in ’05, and I ran into a problem. Issuing
ps2pdf letterhead.eps
would create a letterhead.pdf
, all right, but the bounding box information would be lost and the resulting PDF was a full letter-sized document with the image crammed down in the bottom left corner.
Since ps2pdf can accept basically the same options as Ghostscript, and Ghostscript has about a million options, I figured there had to be a way to maintain the bounding box. After a bit of Ducking2, I found this answer,
ps2pdf -dEPSCrop letterhead.eps
which gave me a perfectly cropped PDF.
Even after finding the answer, I had no memory of ever using the -dEPSCrop
option. So how did I get cropped PDFs back in ’05? I doubt I used Preview because its cropping isn’t very precise. I did have a copy of Illustrator back then, so maybe that’s what I used.
Or maybe I did use -dEPSCrop
and have completely forgotten about it. I hope putting it here means I won’t forget it again.
-
Since this is PostScript, the “points” are PostScript points, which come 72 to the inch. If you’re a TeX user, “points” (
pt
) are the more traditional printer’s points, which come 72.27 to the inch. In TeX, PostScript points go by the name “big points” (bp
). ↩ -
Like “Googling,” but with DuckDuckGo. ↩