【发布时间】:2015-08-05 11:48:38
【问题描述】:
我正在例行裁剪 PDF 并将它们导入 PDF 模板。我正在使用 GhostScript,通过 PHP 脚本中的 exec() 和 FPDI 调用。全部运行在服务器端。
到目前为止,我可以使用this post(设置CropBox)中说明的过程使用 GhostScript 裁剪 pdf 文档。
下一步是对文档的偶数页和奇数页进行不同的裁剪。所以我尝试了SuperUser站点this other post中解释的方法,将自定义PostScript代码传递给GhostScript的-c参数:
-c "<< /CurrPageNum 1 def /Install { /CurrPageNum CurrPageNum 1 add def
CurrPageNum 2 mod 1 eq {28 0 translate} {} ifelse } bind >> setpagedevice"
此方法将奇数页移动 28 pt,对偶数页不执行任何操作。因此,我尝试修改它,传递 CropBox(es)(在 sprintf 句子中将 %s 占位符替换为适当的坐标):
-c "<< /CurrPageNum 1 def /Install { /CurrPageNum CurrPageNum 1 add def
CurrPageNum 2 mod 1 eq {[/CropBox [%s %s %s %s]} {[/CropBox [%s %s %s %s]}
ifelse } bind >> setpagedevice"
这是对 4 页 pdf 文件执行的完整命令:
"C:\Program Files (x86)\gs\gs9.07\bin\gswin32c.exe" -sDEVICE=pdfwrite
-o C:\inetpub\wwwroot\ledrail\tmp\output.pdf
-c "<< /CurrPageNum 1 def /Install { /CurrPageNum CurrPageNum 1 add def
CurrPageNum 2 mod 1 eq {[/CropBox [119.04 168.336 505.92 715.428]}
{[/CropBox [59.52 84.168 505.92 715.428]} ifelse } bind >> setpagedevice"
-f C:\inetpub\wwwroot\ledrail\documentacio\pdf\documentacio_15.pdf
显然,我收到一个错误,因为[/CropBox... 不是有效的 PS 代码。
Error: /typecheck in --.postinstall--
编辑澄清:
所以,我的问题是:我如何将 相当于 两个 CropBox(es)(用于奇数页和偶数页)传递给上面显示的 PostScript 代码?或者,还有另一种方法可以从命令行使用 GhostScript 实现此目的?
显然,我知道 CropBox 不是 PostScript 的有效代码,但有什么替代方案?
【问题讨论】:
标签: php pdf ghostscript postscript