使用PHP + GhostScript的PDF裁剪奇数页 [英] PDF crop even-odd pages with PHP + GhostScript

查看:113
本文介绍了使用PHP + GhostScript的PDF裁剪奇数页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理裁剪PDF的例程,并将其导入PDF模板。我正在使用GhostScript,从PHP脚本和FPDI中通过 exec()进行调用。所有运行的服务器端。

I am working in a routine for crop PDF's and import them into a PDF template. I am using GhostScript, invoked with exec() from a PHP script, and FPDI. All running server-side.

到目前为止,我已经能够使用此信息(设置 CropBox )。

So far, I am able to crop pdf documents with GhostScript using the procedure explained in this post (setting CropBox).

下一步是裁剪文档的偶数和奇数页。因此,我尝试了SuperUser中另一篇文章中介绍的方法站点,将自定义PostScript代码传递到GhostScript的-c参数中:

The next step is to crop differently the even and odd pages of a document. So I tried the method explained in this other post in SuperUser site, passing custom PostScript code into -c parameter to GhostScript:

-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)来修改它(%s占位符被 sprintf 句子中的适当坐标替换):

This method shift odd pages 28 pt, and do none for even pages. So, I tried to modify this, passing CropBox(es) (the %s placeholders are replaced with appropriate coordinates in a sprintf sentence):

-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文件上执行的完整命令:

Here is the full command executed over a 4-page pdf file:

"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代码。

Ovbiously, I get an error, because [/CropBox... is not valid PS code.

Error: /typecheck in --.postinstall--

编辑以澄清:

所以,我的问题是:如何通过 等效于 的两个CropBox(es )(对于奇数页和偶数页)到上面显示的PostScript代码?或者,还有另一种方法可以从命令行通过GhostScript 实现此目标?

So, my question is: how can I pass the equivalent to two CropBox(es) -for odd and even pages- to the PostScript code shown above? Or, there is another method for achieve this with GhostScript from command line?

显然,我知道CropBox不是PostScript有效代码,但是有什么替代方法?

推荐答案

您无法在PostScript中设置 CropBox,因为CropBox不是它不是PostScript语言的一部分,它是PDF专用的。

You can't set a 'CropBox' in PostScript, because CropBox isn't part of the PostScript language, its PDF-specific.

您需要发送带有/ CropBox的/ PAGE pdfmark,如您引用的第一篇文章所述。您没有设置/ Install。

You need to send a /PAGE pdfmark with a /CropBox, as the first post you reference says. You don't set a /Install.

这篇关于使用PHP + GhostScript的PDF裁剪奇数页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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