【发布时间】:2025-12-05 07:45:01
【问题描述】:
我正在尝试生成仅更改第一页尺寸的新 PDF(使用 CropBox)。我用的是How do I crop pages 3&4 in a multipage pdf using ghostscript的修改版
奇怪的是:一切运行正常,但是当我在典型应用程序(预览版、Acrobat 等)中打开 PDF 时,它们要么崩溃,要么我收到“警告:页面尺寸可能超出范围”错误.在 Acrobat 中,即使页数是 2、45、60 或其他任何值,也只会显示一页。
更奇怪的是:我通过电子邮件将 PDF 发送给某人,看看这是否是特定于机器的问题。在 Gmail 中,在 Google Apps 的 PDF 查看器中一切正常。所以这个过程“成功了”,但看起来尺寸或页面大小有些东西让其他应用程序失望了。
我尝试了多个 GS 选项(dPDFFitPage、dPrinted=false、dUseCropBox、将纸张大小更改为不合法的其他选项),但似乎没有任何效果。
我附上了经过此过程并产生这些错误的 PDF 版本。 https://www.dropbox.com/s/ka13b7bvxmql4d2/imfwb.pdf?dl=0
修改后的输出如下。 xmin、ymin、xmax、ymax、height、width 是在更大的脚本中其他地方定义的变量,GS 是其中的一部分。使用pdfinfo抓取数据
gs \
-o output/#{filename} \
-sDEVICE=pdfwrite \
-c \"<</EndPage {
0 eq {
pop /Page# where {
/Page# get
1 eq {
(page 1) == flush
[/CropBox [#{xmin} #{ymin} #{xmax} #{ymax}] /PAGE pdfmark
true
}
{
(not page 1) == flush
[/CropBox [0 #{height.to_f} #{width.to_f} #{height.to_f}] /PAGE pdfmark
true
} ifelse
}{
true
} ifelse
}
{
false
}
ifelse
}
>> setpagedevice\" \
-f #{filename}"
`#{cmd}`
【问题讨论】:
标签: pdf ghostscript