Index


RISC World

DTP - PostScript Manipulation with PSutils

What is PSutils, and what can you do with it?

Dispelling some Myths

Cross platform file compatibility is an ever present concern for RISC OS users who wish to communicate with friends and colleagues on machines running other operating systems. Although we are blessed with excellent applications like EasiWriter which make file transfer across platforms trivial, many RISC OS users avoid "universal file types" like PostScript because of the perception that it is a difficult format to get to grips with. This article will therefore aim to dispel this myth by introducing the reader to PSUtils---a useful suite of tools which will allow you to perform various transformations on your PostScript masterpieces.

Oh so suite

PSUtils is a tool set which includes a number of Perl and UNIX shell scripts as well as "C" programs which work from the command line. Tables 1 and 2 provide a brief outline of some of the more common programs and scripts. (Advanced users should note that the scripts of Table 2 are invaluable for dealing with PostScript which does not comply with Adobe's Document Structuring Conventions).

PS Util Programs

psnup Places multiple logical pages on a page pstops Places and scales multiple logical pages on a page psselect Selects a subset of pages and writes to an output file epsffit Places PostScript code in an EPS file to produce a new bounding box

PS Util Scripts

fixwfwps fixes MS Word for Windows output fixwpps fixes WordPerfect output fixdlsrps fixes dvilaser output

Although some tools like psmerge are easy to use, other utilities like pstops are more difficult to get accustomed to because of the sheer range of options which they offer the user. For the sake of clarity and because of its indispensability in our armoury of PostScript DTP utilities, we will therefore restrict our attention to pstops.

Case Study

Imagine for a moment that you have created a document with TechWriter, Ovation Pro or armTeX and saved the resulting output in A4 as PostScript (Using a PostScript printer driver, set to print to "file"). However you now decide to produce a double-sided A5 booklet which will replace the A4 original. Instead of reprocessing your original file and saving accordingly, it is possible to `directly' manipulate the PostScript with pstops.

But you first have to get used to the options which pstops provides. Typing `pstops' at the RISC OS command prompt yields the following information:

Usage: pstops [-q] [-b] [-wwidth] [-hheight] [-dlwidth]
[-ppaper] [inputfile] [outputfile]

By breaking the options, or `switches' down from left to right (see Table 3), you will notice that pstops offers a range of possibilities which include:

     -q         run quietly
   -b         prevent bind operators in the PostScript prolog from binding
   -w         width used by `w' dimension specifier
   -h         height used by `h' dimension specifier
   -d         draws line of width `dlwidth'  around each page
   -p         paper size with most common options of A3, A4, A5
   pagespecs  determine how pages are combined  
   inputfile  file for processing
   outputfile name of processed file

If you feel a bit confused at this point, don't worry! Perhaps the best advice is to understand what you want to accomplish before translating into pstops' `language'. So if we return to the exercise of manipulating our PostScript file in order to create a double sided A5 booklet on A4 paper from 16 A4 pages, our booklet will be divided like so:

A4 Sheet

Front Page

 

Back Page

 

 

Left

Right

Left

Right

Sheet 1

16

1

2

15

Sheet 2

14

3

4

13

Sheet 3

12

5

6

11

Sheet 4

10

7

8

9

But how do we translate all of the above into information which pstops can process by using the `pagespecs' parameter? The pstops "man" page ("man" is a standard form of online documentation on UNIX and Linux) states that "pagespecs" follows the following syntax:

pagespecs = [modulo:specs specs = spec[+specs][,specs] spec = [-]pageno[L][R][U][&scale](xoff, yoff)]

So we need to manipulate our existing file by writing instructions in pagespecs' syntax which can initially be very daunting. Perhaps the best way of moving towards enlightenment is to break pagespecs' syntax down into its constituent parts so let's have a go. Pstops' man page describes `modulo' as the number of pages in each "block". So if we have 16 pages in total which will be printed on 4 A4 sheets, we can assume that we have four blocks with four pages per block. Furthermore, if we count through our booklet by beginning at "0" and starting again from "0" every fourth page, we end up with the following sequence of `logical' page numbers:

Logical Page Number

0

1

2

3

 

1

2

9

10

 

3

4

11

12

 

5

6

13

14

 

7

8

15

16

Armed with this knowledge we should now be able to place our pages in the correct order by using the `-' and `+' signs to denote one page from the back and one page from the front respectively. If you think about it, our notation for all printed front and back pages will read as follows:

     "4:-3+0" for all front pages.
     "4:+1+-2" for all back pages.

We now have a number of logical A4 pairs side-by-side so our next task is to move, rotate and scale the pages so that 2 A5 pages will fit on one A4 sheet. Beginning with the left-sided front pages, we will need to move the A4 sheet by a distance equal to its width which is 21 cms for an A4 sheet by adding this measurement to our existing pagespec:

     4:-3(21cm,0)+0

and performing the same transformation for our left-sided back pages so our pagespec reads as follows:

     4:1(21cm,0)+-2

A 90 degree anticlockwise rotation around the page's lower left corner can then be accomplished by using the `L' switch so that `4:-3L(21cm,0)+0' rotates left-sided front pages whilst `4:1L(21cm,0)+-2' has the same effect on left-sided back pages.

We can then finally reduce our page size by a factor of 0.7 to create an A5 page. (Remember that reducing the length and width of an A4 page by half will produce a page which is `smaller' than A5).

     4:-3L@0.7(21cm,0)+0
     4:1L@0.7(21cm,0)+-2

And if we also scale our right-sided pages, our specification should read as follows:

     4:-3L@0.7(21cm,0)+0L@0.7
     4:1L@0.7(21cm,0)+-2L@0.7

Great! We are nearly there. All that we need to do now is to move our right -sided pages so that they are adjacent to those on the left. If you think about it, this can be accomplished by moving each right handed page 21 cms horizontally and half an A4 length (14.85cm) upwards:

     "4:-3L@0.7(21cm,0)+0L@0.7(21cm,14.85cm)" for the front pages. 
     "4:1L@0.7(21cm,0)+-2L@0.7(21cm,14.85cm)"  for the back pages.

All that now remains to be done is to combine the specs for all pages by using one `modulo pagespec' at the beginning of our command:

     pstops -pa4 \
     "4:-3L@0.7(21cm,0)+0L@0.7(21cm,14.85cm),1L@0.7(21cm,0)+-2L@0.7(21cm,14.85cm)"
     <input file> <output file>.

And the results of our efforts can be seen in Figure 1. Owners of single-sided printers will however have to take a slightly different approach. Now that you know how to drive pstops, you should be able to work it out for yourself.


Figure 1

Resources

PSUtils for RISC OS is available from www.acornusers.org/ghostscript whilst `ps2pdf' (a useful drag-and-drop utility for those who want to convert to PDF) is available from www.runton.ndo.co.uk. PC Card users can also obtain the suite from the Comprehensive TeX Archive Network at www.tug.org in the support/PSUtils directory whilst ARM Linux users can install PSUtils as a Debian package from www.aleph1.co.uk/armlinux.

RISC OS versions of PSUtils, GhostScript and PS2DPF are all in this issues Software directory.

Paul Webb

 Index