Getting the page sizes of a PostScript document

半腔热情 提交于 2020-03-05 03:55:41

问题


I want to get page size of each page of a PostScript document in a simple program or shell script.

Is there any program or library that can get the page sizes. (Like pdfinfo, but dealing with PostScript)


回答1:


No doubt, there's some program for that, but you can try using Ghostscript:

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

But then you may need to filter out any warnings or DSC comments. E.g. one of test file I found gave me this:

%%[ 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]%%

Putting some markers into your redefined showpage procedure may be helpful.




回答2:


If you can use PostScript level 2, you can use currentpagedevice:

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


来源:https://stackoverflow.com/questions/19954539/getting-the-page-sizes-of-a-postscript-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!