How to set custom page size with Ghostscript

荒凉一梦 提交于 2019-11-28 18:46:59

You can set the used page size with -gNNNNxMMMM where NNMN is the width in pixels at 720 dpi (720 pixels == 1 inch), and MMMM is the height in pixels at 720 dpi.

Or you can set the custom size in PostScript points (72 points == 1 inch) with -dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h.

If I'm not wrong, 9.36 inch ≈= 674 points and 12.67 inch ≈= 912 points.

You'll also have to apply -dPDFFitPage in order to fit your input onto the page.

So you could use either

gs                          \
   -o output.pdf            \
   -sDEVICE=pdfwrite        \
   -dDEVICEWIDTHPOINTS=674  \
   -dDEVICEHEIGHTPOINTS=912 \
   -dPDFFitPage             \
    input.ps

or

gs                   \
   -o output.pdf     \
   -sDEVICE=pdfwrite \
   -r600             \
   -g8112x7596       \
   -dPDFFitPage      \
    input.ps

What worked for me:

gs -sDEVICE=pdfwrite -r720 -g4308x6066 -dPDFFitPage -o out.pdf in.pdf

The 4308x6066 is the number of pixels, the -r720 is the number of pixels per inch.

So here we have 720dpi, so for instance fo 5 inches, this will be 3600 pixels.

I am using GhostPDL 9.10. Though my paper size of 8.5x13 is listed at http://ghostscript.com/doc/7.07/Use.htm#Known_paper_sizes as "flsa" the "-sPAPERSIZE=flsa" switch had no effect, the paper size remained Letter. The correct units for the -g5100x7800 switch matched my -r600 (not 720); -g works.

I found that gs was clipping my output even though I had forced the page to the largest standard size, A0.

The reason turned out to be that the PostScript document sent to gs by groff / grops contained a %%DocumentMedia specification that was overriding Ghostscript's choice.

The solution was to give groff the command-line flag -p-P48i,48i. The -p tells groff to pass the rest of the option to grops. The -P48i,48i to grops sets the paper size to 48 inches by 48 inches.

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