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)
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.