Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: "Chapman Flack" <googrou@xxxxxxxxxxxxxxxx>
- Date: 24 Sep 2005 13:43:10 -0700
Michael Kilpatrick wrote:
> If in the future I get to grips with Postscript I can perhaps follow
> Chapman's procedure and rewrite the perl script so that it adds code
> similar to his to the Postscript without all the additional faffing
Two thoughts occur to me.
1. I should correct 4 more mistakes in the code I posted above, plus
work around an old ghostscript bug I didn't know about. Sheesh. :)
2. If your requirement is just to get as many A3 spreads as possible,
with
at most 1 A4 single, could you live with the A4 coming first? Then
all
your cases collapse to two: you have an odd number of pages (make 1
A4
page, then all spreads) or even (make all spreads). Nowhere do you
need
code that bothers with determining the last page. (You will still
need a
script that counts the pages anyway, but the manipulation gets
simpler.)
This code might do the trick (and also addresses point 1. :)
vmstatus pop pop 0 eq { save pop } if % older gs workaround
currentglobal true setglobal
<<
/ODD [ //true ] % or //false, set this according to the pagecount
/mm { 72 25.4 div mul }
/postshow [ null ]
>> dup begin
/showpage { showpage //postshow 0 get dup null eq { pop } {
//postshow 0 null put exec
} ifelse
} bind end def begin % this is why I dup'd the dictionary above
//ODD 0 get {
<< /PageSize [ 210 mm 297 mm ] >> setpagedevice
//postshow 0 {
<< /PageSize [ 420 mm 297 mm ] >> setpagedevice
//ODD 0 //false put
} bind put
} {
<< /PageSize [ 420 mm 297 mm ] >> setpagedevice
} ifelse
<<
/BeginPage { 2 mod 1 eq { 210 mm 0 translate } if } bind
/EndPage { 0 eq exch 2 mod 1 eq //ODD 0 get or and } bind
>> setpagedevice
end setglobal
How to use it: prepend it to the file, only changing the definition of
ODD (//true or //false) depending on the number of pages in the file,
which you will need to know in advance.
What it does:
1. defines (as before) a version of showpage that executes postshow if
non-null.
2. If ODD, sets the initial paper selection to A4, and sets postshow to
a
procedure to reset A3 landscape, and clear ODD, after the very first
showpage.
3. Sets BeginPage to do nothing when the interpreter's pagecount is
even,
and translate 210 mm right when odd. This works without keeping my
own
pagecount as I did before, because now it is convenient that the
built-in
count resets to zero with setpagedevice. It means the first page (0)
will
be placed unshifted, which is correct in the ODD or nonODD case; if
ODD,
the following setpagedevice changing the paper selection will reset
the
count so the next page will be 0 again, placed unshifted on the A3
***,
and thereafter odds will be shifted and evens unshifted on A3
sheets.
4. Sets EndPage to return true (printing a ***) only in the case of
showpage
(reason code 0) only when the page count is odd (second page of each
A3
spread) or ODD is true (first page in the ODD case).
The three mistakes I corrected from the first posting:
1. Inside a dictionary created with << >>, definitions are not followed
by
'def', except when I am typing without thinking.
2. I defined mm simply as the conversion factor, a number, but used it
later
as if it were a procedure multiplying by that number. So here I've
defined
it that way. :)
3. And for all that, I had written '210 0 translate' instead of
'210 mm 0 translate' - so it would have shifted things by 210
PostScript
points (about 74 mm) instead of by 210 mm.
4. Without ensuring my variables like ODD and postshow go in global
memory,
I can't be sure 'restore' operators in the following PostScript
document
won't undo updates to them. :O
The old ghostscript bug (it's fixed in 8.15) involved acting like a job
server at save level 0 by default, so I threw in a line to make sure
the save level isn't zero, which won't hurt anywhere.
Sorry to have complicated your getting acquainted with PostScript, by
throwing
bogus code at you.
To use the above, you'd still need a script to get the page count from
a PS file to see if it is odd or even. Here's a simple way:
#!/bin/sh
# name this script pspgct
# usage: pspgct filename
<<EndPrologue cat - "$1" | # pipeline resumes below
vmstatus pop pop 0 eq { save pop } if
currentglobal true setglobal
<< /pcnt [ 0 ] >> begin
setglobal
<< /EndPage { 0 eq { //pcnt 0 2 copy get 1 add put } if pop //false }
bind >>
setpagedevice
{ end currentfile cvx exec //pcnt 0 get = } bind exec
EndPrologue
# pipeline resumes here ->|
gsnd -q -
The script just puts the 7 lines of PS in front of the PS file and
pipes to ghostscript; the 7 lines create a pcnt variable, and set up an
EndPage that always returns false (never produce a page), but
increments pcnt every time it is called with reason code 0 (that is, by
a real showpage, not some other event). The last line just executes the
rest of the current file to the end, then prints pcnt.
.
- Follow-Ups:
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- References:
- Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Aandi Inston
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Aandi Inston
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Aandi Inston
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Jim Land
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: John Reiser
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Chapman Flack
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Chapman Flack
- Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- From: Michael Kilpatrick
- Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- Prev by Date: Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- Next by Date: Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- Previous by thread: Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- Next by thread: Re: Turning 3 pages of A4 into a 2-up A3 spread and 1 A4 ***?
- Index(es):