如何使用Ghostscript将PDF的大小精确调整为8.5 x 11英寸? [英] How do I resize a PDF to be exactly 8.5 x 11 inches using Ghostscript?

查看:229
本文介绍了如何使用Ghostscript将PDF的大小精确调整为8.5 x 11英寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑此PDF .我正在尝试使用以下命令将其转换为标准字母大小(8.5 x 11).

Consider this PDF. I am trying to convert it to standard letter size (8.5 x 11) using the following command.

gs -dFIXEDMEDIA -dBATCH -dNOPAUSE -sPAPERSIZE=letter \
   -dPDFFitPage -q -sDEVICE=pdfwrite -sOutputFile=out.pdf \
    dean08mapreduce.pdf

这是输出中的pdfinfo.

Producer:       GPL Ghostscript 9.10
CreationDate:   Mon Nov 17 18:25:01 2014
ModDate:        Mon Nov 17 18:25:01 2014
Tagged:         no
Form:           none
Pages:          7
Encrypted:      no
Page size:      596.225 x 792 pts
Page rot:       0
File size:      126908 bytes
Optimized:      no
PDF version:    1.4

以下是原件上的pdfinfo:

Producer:       Creo Normalizer JTP
CreationDate:   Fri Dec 21 09:09:07 2007
ModDate:        Fri Dec 21 14:46:23 2007
Tagged:         no
Form:           AcroForm
Pages:          7
Encrypted:      no
Page size:      603 x 801 pts
Page rot:       0
File size:      235239 bytes
Optimized:      yes
PDF version:    1.3

请注意,输出具有正确的高度,但没有正确的宽度.它实际上是8.3 x 11,而不是8.5 x 11.

Notice that the output has the correct height but not the correct width. It is effectively 8.3 x 11, not 8.5 x 11.

我在此处此处,但都没有达到我的要求.

I have tried the solutions here and here but neither achieves what I require.

如何强制PDF完全为8.5 x 11?

How can I force the PDF to be exactly 8.5 x 11?

我不介意是否要在两边添加一点空白.

I do not mind if it involves adding a little whitespace on either side.

推荐答案

双重转换不是一个好计划,您可能会在每个步骤中引入问题,特别是因为PostScript不支持PDF的图形模型(特别是它支持不支持透明性

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)

您的问题是原始PDF文件包含一个CropBox,该文件夹由Ghostscript pdfwrite设备保留. pdfinfo的输出告诉您PDF文件的大小,同时考虑了CropBox的大小. MediaBox实际上是612x792,即恰好是8.5x11,这正是您想要的.

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.

给定高度的原因是因为新的MediaBox位于原始CropBox的内部,所以它是给定的两个盒子的交集.

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.

如果您不希望保留CropBox,则必须构造一个新的CropBox Page或PAGES pdfmark并将其作为PostScript发送.这并不是完全不平凡的.在您的情况下,每个页面都有一个CropBox(不是整个文档的默认值),因此您需要在每个页面上覆盖CropBox.为此,您需要定义一个/EndPage过程,该过程使用pdfmark设置所需的CropBox,并在处理该PDF文件之前发送.

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.

此:

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

为我工作.

这篇关于如何使用Ghostscript将PDF的大小精确调整为8.5 x 11英寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆