1

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)

Sherwood Wang
  • 685
  • 9
  • 19

2 Answers2

4

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.

user2846289
  • 2,185
  • 13
  • 16
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
prewett
  • 1,587
  • 14
  • 19
  • The answer is duplicated with the accepted one. And it's not matching what I asked "... in a simple program or shell script". – Sherwood Wang Feb 13 '17 at 08:58
  • Fair enough. I think I actually meant to post this in answer to a different SO question asking more or less the same thing, minus the script part. On the answer they mixed up 0 and 1. Unfortunately, I mixed up the question :( – prewett Feb 26 '17 at 08:11