質問

I'm having troubles with ghostscript 9.10 apparently removing content outside of the crop box (specifically the crop marks I've put there)

This is the PDF before using ghostscript: with_cropbox_before_optimize.pdf

$ pdfinfo -box with_cropbox_before_optimize.pdf
  MediaBox:           0.00     0.00   651.97   898.58
  CropBox:           28.35    28.35   623.62   870.24

Setting the viewer to display the entire media box shows the crop marks outside of the crop box as expected. (the black border is there to illustrate where the crop box would be)

Then I'm calling:

gs -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dCompatibilityLevel=1.7 \
-dNOPAUSE -dQUIET -dBATCH -dAutoRotatePages=/None -sOutputFile=<out.pdf> <in.pdf>

Which yields the following file: with_cropbox_after_optimize.pdf

Now the crop marks are missing or at least they are no longer being displayed - the page dimensions are still fine however, so it hasn't cropped it or something...

$ pdfinfo -box with_cropbox_after_optimize.pdf
  MediaBox:           0.00     0.00   651.97   898.58
  CropBox:           28.35    28.35   623.62   870.24

So: Am I doing it wrong or is this a bug?

役に立ちましたか?

解決

The first thing to understand (I know I keep mentioning this, but people don't understand it) is that Ghostscript and pdfwrite are not simply twiddling with your PDF fikle.

The input PDF file is interpreted and the PDF marking operations are converted into internal graphical primitives which are then passed through the Ghostscript device interface. In general these primitives are then rendered to a bitmap. In the case of pdfwrite, the primitives are reconverted into PDF marking operations, and a brand new PDF file assembled from them. The output bears no relation to the input, other than its visual appearance.

So when you process your PDF file with Ghostscript you are not 'optimising' it, you are creating a brand new PDF file.

In your case the objects outside the CropBox are not interpreted (because they are outside the CropBox, they are cropped). As an obvious result they are not passed through the device interface, and therefore not present in the output PDF file.

Note that while Ghostscript crops to the CropBox, that doesn't affect the MediaBox, so the media is still the same but cropped objects are cropped out. You can use -dUseCropBox to alter the media to be the same as the CropBox, but that's not what you want.

Right at the moment I can't see where the CropBox is converted into a clip, so your best solution is probably to create the file without a CropBox (or remove it, or set it to the MediaBox) and then add it in using a pdfmark when processing the file.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top