I don't know the postscript language.

I have a duplex printing emulation system written in bash. It prints the odd pages first and then the even pages. It needs to know if there's an odd page count so it can eject the last odd page that doesn't have a corresponding even side. It also uses page counts for reporting purposes.

I didn't know how to do this correctly, so I wrote code that looks at the end and, if necessary, the beginning of the postscript file searching for "%%Pages:" which is followed by a page count. This works on almost everything except files printed by the Opera browser.

Can anyone suggest another way to get this information?

Postscript files tend to be rather large with a lot of non-human-readable content, so I haven't yet spent a lot of time pouring over the ones that come out of Opera.

TIA

The current code is at:

http://sourceforge.net/projects/duplexpr/

function ps_page_ct
link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

Unfortunately, there is no simple way of finding pages in a raw Postscript file. That is why %%Pages convention has been created (Adobe Document Structuring Conventions).

The command for issuing a page is showpage. In simple cases, you just have to count them.

But this command can be embedded in the body of a function and then you need a Postscript parser.

link|improve this answer
+1 for what is, ultimately, the correct answer. Postscript is a Turing-complete language. If you want an accurate answer, interpreting the file is the "One True Way". I'd start seriously looking at leveraging Ghostscript if you really need this. – afrazier Dec 9 '11 at 13:48
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.