How can I add a footer to the bottom of each page of a postscript or pdf file in linux?

In your PostScript file you can use a page counter and redefine showpage to display it in the footer. Here's a sample program:

4 dict begin

/showpage_org /showpage load def            % you'll need this later!  
/page_num 0 def  
/page_str 3 string def                      % Page numbers -99 to 999 supported, error if > 3 char

/showpage                                   % with page number footer  
{  
    gsave
    /Courier findfont 10 scalefont setfont  % Set the font for the footer  
    /page_num page_num 1 add def            % increment page number counter  
    10 10 moveto (Page ) show                 
    page_num page_str cvs show              % convert page number integer to a string and show it  
    grestore  
    showpage_org                            % use the original showpage  
} def  

%Page 1  
/Courier findfont 22 scalefont setfont  
100 500 moveto (Hello) show  
showpage  

%Page 2  
100 500 moveto (World) show  
showpage  

end

ESP Ghostscript is O-o-o-o-old. Don't use it any more unless you absolutely, absolutely cannot avoid it. It was a fork of the original Ghostscript which used by CUPS for a while. (And after some problems between developers where resolved, more recent versions of CUPS now also use the GPL Ghostscript again...)

Newer GPL Ghostscript versions are here: http://www.ghostscript.com/releases/

Also, -o out.pdf is only a shorthand for -dBATCH -dNOPAUSE -sOutputFile=outpdf. So you should try this. (The -dNOPAUSE part relieves you from hitting <return> for every page advance....).

Lastly, don't expect the full range of documentation being provided by a third party man gs page. Rather refer to the original Ghostscript documentation for the version you use, the most important parts being:

  • current development branch: Readme.htm + Use.htm + Ps2pdf.htm
  • 9.00 release: Readme.htm + Use.htm + Ps2pdf.htm
  • 8.71 release: Readme.htm + Use.htm + Ps2pdf.htm

Update: Ghostscript has moved to Git (instead of Subversion) for their source code repository. Therefor the following links have changed, repeatedly:

  • current development branch: Readme.htm + Use.htm + Ps2pdf.htm
  • current development branch: Readme.htm + Use.htm + Ps2pdf.htm