Ghostscript 获取PostScript文档的页面大小

Ghostscript 获取PostScript文档的页面大小,ghostscript,postscript,Ghostscript,Postscript,我想在一个简单的程序或shell脚本中获得PostScript文档每页的页面大小 是否有任何程序或库可以获取页面大小。(与pdfinfo类似,但处理PostScript)毫无疑问,有一些程序可以实现这一点,但您可以尝试使用Ghostscript: gs -q -sDEVICE=nullpage -dBATCH -dNOPAUSE \ -c '/showpage{currentpagedevice /PageSize get{=}forall showpage}bind def' \ -f tes

我想在一个简单的程序或shell脚本中获得PostScript文档每页的页面大小


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

毫无疑问,有一些程序可以实现这一点,但您可以尝试使用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
过程中添加一些标记可能会有所帮助。

毫无疑问,有一些程序可以实现这一点,但您可以尝试使用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
过程中放置一些标记可能会有所帮助。

如果可以使用PostScript 2级,则可以使用
currentpagedevice

/pagewidth  currentpagedevice /PageSize get 0 get def
/pageheight currentpagedevice /PageSize get 1 get def

如果可以使用PostScript级别2,则可以使用
currentpagedevice

/pagewidth  currentpagedevice /PageSize get 0 get def
/pageheight currentpagedevice /PageSize get 1 get def

答案与已接受的答案重复。而且它与我所要求的“在一个简单的程序或shell脚本中”不匹配。这很公平。我想我实际上是想在回答一个不同的问题时发表这篇文章,问的或多或少都是相同的问题,不包括脚本部分。他们在答案上把0和1混淆了。不幸的是,我把问题弄混了:(答案与被接受的答案重复。而且它与我所问的不匹配“…在一个简单的程序或shell脚本中”.很公平。我想我实际上是想在回答一个不同的问题时发布这篇文章,问的问题或多或少是相同的,不包括脚本部分。在回答中,他们混淆了0和1。不幸的是,我混淆了问题:(