Frage

I'm using the Domestic shipping label api in usps to generate domestic shipping labels in pdf format. I managed to crop the top section of the pdf file which is the label needed by the usps and Ignored the bottom section which is the receipt which is not needed in shipping.

I use Ghostscript /Cropbox to crop the section that I only want which is successful but when I try to print the cropped pdf file in linux cups I get the whole uncropped pdf printed instead of the cropped pdf file. Why is it still printing the whole file instead of just printing the cropped section?.

Here's the script I'm using to crop the usps Shipping label.

gs -o cropped.pdf -sDEVICE=pdfwrite -c "[/CropBox [50.4 460.5 484.4 750.5] /PAGES pdfmark" -f uncropped.pdf

Then to change its orientation to portrait i use pdftk

pdftk cropped.pdf cat 1L output cropped_portrait.pdf

To print it in linux cups I'm using the command.

lp cropped_portrait.pdf

But when i print it it is printing the uncropped.pdf file instead of cropped_portrait.pdf. Why is it doing that? I even deleted uncropped.pdf and tried printing again but it still prints uncropped.pdf.

Here's the two files the uncropped and cropped usps shipping labels.

Uncropped PDF file Uncropped PDF file

Cropped PDF file

enter image description here

Hope you can help me on this one,

Thank you

War es hilfreich?

Lösung

Presumably the reduced PDF file displays correctly, so there is no problem with Ghostscript producing the PDF file.

As to why the printing process doesn't respect the CropBox, there is no reason really why it should. There are many Boxes in PDF and no real way for a print application to know which one you want to use. As a result printing applications often default to the MediaBox, which you haven't altered (Note that altering the CropBox doesn't change the content of the PDF file, just what is displayed).

Now, if your CUPS chain is using Ghostscript to render the PDF file, or convert it to PostScript, then this can be solved, you need to add -dUseCropBox to the command line. However I'm not a CUPS expert so I can't tell you how to do that. If CUPS isn't using Ghostscript then its probably still possible to instruct whatever is doing the conversion to use the CropBox, but you're going to have to find out what application is involved and alter the command appropriately for that application.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top