使用Ghostscript调整PDF大小 [英] Resizing a PDF using Ghostscript
问题描述
我正在尝试将PDF缩放为例如A4大小的小到A4.
I am trying to scale a PDF which is for example just small of A4 size up to A4.
这对于纵向文档很好用.正确缩放文档,然后将填充添加到顶部.
This works fine with portrait documents. The document is scaled up correctly and then padding is added to the top.
在横向文档上,虽然未添加填充.因此,文档最终将成为A4的正确高度,但由于没有在文档一侧添加填充(我希望如此),因此宽度不够宽.
On landscape documents padding is not added though. Therefor the document will end up being the correct height for A4 but then not wide enough, as padding is not added on the document side (as I hoped).
这是我用于A4纵向文档的方法:
This is what I use to have it working for A4 portrait documents:
gs \
-sOutputFile=output.pdf \
-sDEVICE=pdfwrite \
-sPAPERSIZE=a4 \
-dCompatibilityLevel=1.4 \
-dNOPAUSE \
-dBATCH \
-dPDFFitPage \
input.pdf
推荐答案
您应该添加-dFIXEDMEDIA
开关:
gs \
-o output.pdf \
-sDEVICE=pdfwrite \
-sPAPERSIZE=a4 \
-dFIXEDMEDIA \
-dPDFFitPage \
-dCompatibilityLevel=1.4 \
input.pdf
如果需要强制使用特定的纸张/页面/介质尺寸,而忽略文档中指定的纸张/页面/介质尺寸,则始终需要
-dFIXEDMEDIA
.因为PDF始终定义了纸张/页面/介质的尺寸(PostScript可能有,也可能没有...).
-dFIXEDMEDIA
is always required if you need to force a specific paper/page/media size and ignore the paper/page/media size specified in the document. Because PDF always has a paper/page/media size defined (PostScript might have, or might not have...).
(我的-o ...
较短,并且省去了添加-dBATCH -dNOPAUSE
的麻烦-但仅适用于最新版本的Ghostscript.)
(My -o ...
is shorter and saves one from adding -dBATCH -dNOPAUSE
-- but works only for more recent versions of Ghostscript.)
这篇关于使用Ghostscript调整PDF大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!