2 % Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
4 % This software is provided AS-IS with no warranty, either express or
7 % This software is distributed under license and may not be copied,
8 % modified or distributed except as expressly authorized under the terms
9 % of the license contained in the file LICENSE in this distribution.
11 % For more information about licensing, please refer to
12 % http://www.ghostscript.com/licensing/. For information on
13 % commercial licensing, go to http://www.artifex.com/licensing/ or
14 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
15 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
17 % $Id: gsnup.ps,v 1.5 2005/06/07 19:24:33 ray Exp $
18 % Prefix this to very well-behaved PostScript files for n-up printing.
20 /cdef { 1 index where { pop pop } { def } ifelse } def
22 %%%%%%%%%%%%%%%% Begin parameters %%%%%%%%%%%%%%%%
24 % All parameters are also settable from the command line with -d, e.g.,
27 /.Nx 2 cdef % # of pages across the physical page
28 /.Ny 2 cdef % # of pages down the physical page
29 /.Landscape false cdef % if true, rotate page by 90 degrees
31 %%%%%%%%%%%%%%%% End parameters %%%%%%%%%%%%%%%%
33 vmstatus pop pop 0 eq { save pop } if
35 currentpagedevice /PageSize get aload pop
37 1 dict dup /PageSize 4 -1 roll put
40 /.BP currentpagedevice /BeginPage get def
41 /.EP currentpagedevice /EndPage get def
42 /.Ps 1 string def % survive save/restore
43 /.Pn { .Ps 0 get } def
44 true setglobal % protect from restore
48 /.max { 2 copy lt { exch } if pop } cdef
49 % Work around the common save ... showpage ... restore locution.
51 .Rmat currentmatrix pop restore
52 vmstatus pop pop .ELevel 0 get lt { .Rmat setmatrix } if
58 initclip clippath pathbbox exch 4 -1 roll sub 3 1 roll exch sub
60 2 copy exch .Nx div exch .Ny div
61 .Pn dup .Nx mod exch .Nx idiv .Ny 1 sub exch sub
62 % Stack: nmax pw ph pw/nx ph/ny ix iy
63 exch 3 index mul exch 2 index mul
65 % Stack: nmax pw ph pw/nx ph/ny
66 4 -1 roll 4 index div 4 -1 roll 4 index div
67 % Stack: nmax pw/nx ph/ny pw/nmax ph/nmax
68 exch 4 -1 roll exch sub 2 div
77 .ELevel 0 vmstatus pop pop put
78 .Ps 0 .Pn 1 add .Nx .Ny mul mod put
90 { .Pn 0 eq { exit } if showpage } loop
93 { currentfile cvx exec .EOJ } exec