问题
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