On 23-Apr-07 01:49:14, Carlos E. R. wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
> Hi,
> 
> Is there a way to add page numbers to the pages of a postscript
. file, so that they print in the paper?
> 
> I have done this in the past with a2ps or similar, but this time
> the original is a ps file.
> 
> I can, for instance, use "psnup -2 infile.ps outfile.ps" to
> rearrange it two pages per sheet, and I can print odd pages first,
> then even on the other side, and thus get 4 pages per sheet and
> save trees. But unless I number them with pencil I can easily get
> lost when ordering them.
> 
> So the question is, how can I add the page numbers automatically?

In principle yes, but whether it is straightforward in practice
depends on the contents of the PostScript file (PS is such a
generalised language that there are many many ways in which the
same printed content can be represented in PsotScript).

The most favourable case is a PS file which is entirely plain
ASCII text with no hex-encoded content, and which contains DCS
("Document Structuring Convention") comments.

Such a comment always begins with "%%" at the start of a line,
such as

%%Pages: 4
%%PageOrder: Ascend
%%Orientation: Portrait

etc.

In that case, you will probably find DSC comments like

%%Page: 1 1
%%BeginPageSetup
<PostScript Code>
%%EndPageSetup
<More PostScript Code>

This is the best place for an automated page-numbering
system to start from. The following assumes that you
want the page number to be 1 inch (72 points) up from the
bottom of the page, and 1 inch in from the left, and that
the standard coordinate system is in operation (some
software may, for instance, invert the vertical so that
distance is measures from the top rather than the default
bottom of the page -- in which case the numbers will not
only be at the top left, but also upside down!).

%%Page: requires two arguments: the first is a page label
(which may be anything), and the second is a sequential
page number, starting from 1 at the first page of the
document. E.g.
%%Page: Title 1
%%Page: i 2
%%Page: ii 3
%%Page: 1 4
etc.

DSC Comments are not printed, but are there to assist
display software in displaying the document (e.g. jumping
to a particular page, and displaying page number and/or
label in a status box).

In that case, you can feed your PS file through an 'awk'
script in order to plant PS commands to print the (sequential)
page number. Example:

#! /bin/bash
awk '
{print $0}
/^%%Page:/{Pno = $3}
/^%%EndPageSetup/{
  print( "gsave" )
  print( "/Times-Roman findfont 12 scalefont setfont" )
  print( "72 72 moveto" )
  print( "(" Pno ") show" )
  print( "grestore" )
}'


Store the above as a file, say "numps.awk", and make it
executable:

  chmod 755 numps.awk

and then:

  cat myfile.ps | ./numps.awk > mynewfile.ps

Check it with:

  gv mynewfile.ps

and if it's OK then you can print it!

As I say, whether the above will work as intended depends
on how the PS file was created. If it has non-standard
features which interfere (e.g. inverted coordinates as
above) then the 'awk' script would need to be amended
accordingly. But at least this illustrates the principle.

Also, a PS file need not contain DSC comments at all, in
which case the above will not work, and a different
approach would have to be worked out.

Hoping this helps!
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 23-Apr-07                                       Time: 14:54:27
------------------------------ XFMail ------------------------------
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to