How do I resize a PDF to be exactly 8.5 x 11 inches using Ghostscript?

ぐ巨炮叔叔 提交于 2019-12-01 09:21:50
KenS

Double conversion isn't a good plan, you potentially introduce problems at every step, especially since PostScript does not support the graphics model of PDF (in particular it does not support transparency)

Your problem is that the original PDF file contains a CropBox, which is retained by the Ghostscript pdfwrite device. The output from pdfinfo is telling you the size of the PDF file, taking the CropBox into account. The MediaBox is in fact 612x792, ie exactly 8.5x11, which is what you wanted.

The reason the height is given differently is because the new MediaBox is inside the original CropBox, so it is the intersection of the two boxes being given.

If you don't want the CropBox to be preserved, you will have to construct a new CropBox Page or PAGES pdfmark and send it as PostScript. This isn't entirely non-trivial; in your case each page has a CropBox (its not a single default for the entire document), so you need to override the CropBox on each page. To do this you need to define a /EndPage procedure which sets the desired CropBox using a pdfmark, and send that before you process the PDF file.

This :

gs -sDEVICE=pdfwrite \
   -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -dFIXEDMEDIA \
   -sOutputFile=out.pdf \
   -c "<</EndPage {0 eq {[/CropBox [0 0 612 792] /PAGE pdfmark true}{false}ifelse}>> setpagedevice" \
   -f dean08mapreduce.pdf

Worked for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!