获取PostScript文档的页面大小

时间:2013-11-13 13:02:47

标签: ghostscript postscript

我希望在简单的程序或shell脚本中获取PostScript文档的每个页面的页面大小。

是否有任何可以获取页面大小的程序或库。 (像pdfinfo,但处理PostScript)

2 个答案:

答案 0 :(得分:2)

毫无疑问,有一些程序,但您可以尝试使用Ghostscript:

gs -q -sDEVICE=nullpage -dBATCH -dNOPAUSE \
-c '/showpage{currentpagedevice /PageSize get{=}forall showpage}bind def' \
-f test.ps

但是,您可能需要过滤掉任何警告或DSC评论。例如。我找到的一个测试文件给了我这个:

%%[ ProductName: GPL Ghostscript ]%%
(Warning: Job contains content that cannot be separated with on-host methods. Th
is content appears on the black plate, and knocks out all other plates.)
595.28
841.89
%%[Page: 1]%%
%%[LastPage]%%

在重新定义的showpage程序中添加一些标记可能会有所帮助。

答案 1 :(得分:1)

如果您可以使用PostScript level 2,则可以使用currentpagedevice

/pagewidth  currentpagedevice /PageSize get 0 get def
/pageheight currentpagedevice /PageSize get 1 get def
相关问题