TigerInALoop
TigerInALoop

Reputation: 225

Extract CropBox as MediaBox from PDF file and leave original fonts

I've tried to find answer here and use GhosScript, but I couldn't succeed.

So, I have a PDF file with CropBox and MediaBox defined. The CropBox/MediaBox ratio differs between pages (especially between title page and rest of the document). What I want to achieve is to extract CropBox from each page and render new PDF with it's MediaBox eqal to CropBox. Basically, I want to trim all of the pages to Cropbox and have MediaBox eqal to this CropBox on each page.

Can I do it using ghostscript or any other cmd-line tool?

EDIT,

I've finally managed how to achieve this with Ghostscript:

gs -dUseCropBox -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf in.pdf

But during conversion I'm getting messages such as:

Page 74 Substituting font Helvetica for KAENAW+Helvetica.

Does it mean that for simple cropping operation I do need to have all of the fonts used by original pdf installed in my system? Is it how ghostscript work? I thought, that the pdf doesn't need to be "rerendered" but this would be some operation on internal dimensions data.

Upvotes: 0

Views: 614

Answers (1)

KenS
KenS

Reputation: 31199

Without seeing your file its impossible to say for sure what's going on.

Most likely your original file doesn't contain an embedded copy of Helvetica (though as its a subset it certainly should!). PDF files are permitted to not contain the 'base 14' fonts, which includes Helvetica, probably your file doesn't, and so Ghostscript is using its own version of Helvetica, that's what's supposed to happen when the base 14 fonts are missing, you can leave them out because all PDF consumers are guaranteed to have them.

Ghostscript's pdfwrite device does not (generally, there are exceptions) render the PDF file, but the default setting of EmbedAllFonts is true I think, so the pdfwrite device will embed a copy of Helvetica in the PDF file it creates, using its own copy to do so.

If you post a file somewhere I can have a look. You should also make sure you are using the current version of Gho stscript.

Upvotes: 0

Related Questions