Myths and Truth about `-sDEVICE=bbox` (was: [cups.development] Filters and rotation)

pipitas pipitas at gmail.com
Sun Jul 29 04:17:15 PDT 2012


On 4/1/11 15:34, Johannes Meixner wrote:

> If you can get the actual PostScript which Ghostscript gets as input
> as a file (e.g. gs-input.ps) run Ghostscript with its "bbox" device
> (e.g. "gs -sDEVICE=bbox gs-input.ps") to get the actual PostScript
> bounding box values which show if the actual PostScript has
> landscape dimensions (i.e. if it is wider than high).

I think you have been fallen prey to a *VERY* common misunderstanding
about what the "-sDEVICE=bbox" parameter *really* does:

* It does not print the "actual PostScript bounding box values",
   nor does it reveal "if the actual PostScript has landscape
   dimensions".

* Instead, it renders each page and just prints the coordinates of
   the *minimal box which contains any marking on the page* at all.

Consider a PDF created by this command:

   gs \
    -o mixed-portrait+landscape-empty-pages.pdf \
    -sDEVICE=pdfwrite \
    -c "<</PageSize [595 842]>> setpagedevice showpage" \
    -c "<</PageSize [842 595]>> setpagedevice showpage"

It creates two empty A4 pages, the first one in portrait, the
second one in landscape orientation. Now run:

   gs -o /dev/null -sDEVICE=bbox mixed-portrait+landscape-empty-pages.pdf

to see this:

   Page 1
   %%BoundingBox: 0 0 0 0
   %%HiResBoundingBox: 0.000000 0.000000 0.000000 0.000000
   Page 2
   %%BoundingBox: 0 0 0 0
   %%HiResBoundingBox: 0.000000 0.000000 0.000000 0.000000

It doesn't even change much if you create the PDF *with* markings
on the pages:

   gs \
    -o mixed-portrait+landscape-empty-pages.pdf \
    -sDEVICE=pdfwrite \
    -c "/F1 {/Helvetica findfont 36 scalefont setfont} def" \
    -c "/mark {100 550 moveto F1 (hello world) show} def" \
    -c "<</PageSize [595 842]>> setpagedevice mark showpage" \
    -c "<</PageSize [842 595]>> setpagedevice mark showpage"

Now the `bbox` output becomes:

   Page 1
   %%BoundingBox: 102 549 270 577
   %%HiResBoundingBox: 102.527434 549.180264 269.851773 576.251982
   Page 2
   %%BoundingBox: 102 549 270 577
   %%HiResBoundingBox: 102.527434 549.180264 269.851773 576.251982

And no, it's not a bug in `bbox` -- it's the *feature*.

It doesn't tell you *anything* about landscape or portrait, and
it's not even meant to do so....


Cheers, Kurt






More information about the cups-devel mailing list