ghostscript fonts - linux

I'm trying to get ghostscript to render a pdf file from a Windows box. The pdf file uses the ComicSansMS font. I've copied the comic.ttf file from my Windows7 box into my /usr/share/ghostscript/fonts directory, and I've created a Fontmap file in that same directory containing this line:
/ComicSansMS (comic.ttf) ;
As nearly as I can tell, the font is not being found despite this. The text comes out very poorly, and some of the smaller font sizes are rendered half the size they should be. Access times and strace show that the Fontmap file is being read, but the font file (comic.ttf) is not being accessed at all. There are no error messages:
hope 78$ gs cards-01.pdf
GPL Ghostscript 9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
>>showpage, press <return> to continue<<
If I use -dFAPIDEBUG on the gs command line, I see the following:
hope 74$ gs -dFAPIDEBUG -I/usr/share/ghostscript/fonts cards-01.pdf
GPL Ghostscript 9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
FAPIhook --nostringval--
Trying to render the font Font --nostringval-- ( aliased from ComicSansMS ) with FAPI...
Font --nostringval-- ( aliased from ComicSansMS ) is being rendered with FAPI=FreeType
FAPIhook --nostringval--
Font --nostringval-- ( aliased from ComicSansMS ) is mapped to FAPI=FreeType
FAPIhook RVJCAL+SymbolMT
Trying to render the font Font RVJCAL+SymbolMT with FAPI...
Font RVJCAL+SymbolMT is being rendered with FAPI=FreeType
FAPIhook RVJCAL+SymbolMT
Font RVJCAL+SymbolMT is mapped to FAPI=FreeType
FAPIhook HYLUQF+ComicSansMS
Trying to render the font Font HYLUQF+ComicSansMS with FAPI...
Font HYLUQF+ComicSansMS is being rendered with FAPI=FreeType
FAPIhook HYLUQF+ComicSansMS
Font HYLUQF+ComicSansMS is mapped to FAPI=FreeType
>>showpage, press <return> to continue<<
Naturally, the line from the above that most concerns me is this one:
Font --nostringval-- ( aliased from ComicSansMS ) is being rendered with FAPI=FreeType
"gs -h" shows that the font directory is, indeed, in the search path:
hope 77$ gs -h
GPL Ghostscript 9.00 (2010-09-14)
[ ... ]
Search path:
/usr/share/ghostscript/9.00/Resource/Init :
/usr/share/ghostscript/9.00/lib :
/usr/share/ghostscript/9.00/Resource/Font :
/usr/share/ghostscript/fonts : /usr/share/fonts/Type1 : /usr/share/fonts
I've tried several permutations of formatting in the Fontmap file, including:
(Comic Sans MS) (comic.ttf) ;
(ComicSansMS) (comic.ttf) ;
/Comic Sans MS (comic.ttf) ;
/ComicSansMS /comic.ttf ;
I'm fairly sure my original one is the correct one, but I was getting desperate. :-P
Any help would be greatly appreciated. Thanks in advance.

I assume that PDF does not have the ComicSansMS font embedded?
You should consider 2 other possibilities as well:
Your PDF file card-01.pdf is somehow corrupted. (Are other PDF viewers rendering that file without a problem? Does it display OK in Acrobat Reader on Widnows?)
Your fontfile comic.ttf is somehow corrupted. (Which method did you use to transfer it from Windows to Linux?)
You could try to positively proof that both these components are getting along well enough with each other by using Ghostscript+comic.ttf to create a PDF (with comic.ttf embedded):
gs \
-sFONTPATH=/usr/share/ghostscript/fonts \
-o comic-ttf.pdf \
-sDEVICE=pdfwrite \
-g5950x8420 \
-c "200 700 moveto" \
-c "/ComicSansMS findfont 60 scalefont setfont" \
-c "(comic.ttf) show showpage"
On Windows, use this variation of above command:
gswin32c.exe ^
-o comic-ttf.pdf ^
-sDEVICE=pdfwrite ^
-sFONTPATH=c:/windows/fonts ^
-g5950x8420 ^
-c "200 700 moveto" ^
-c "/ComicSansMS findfont 60 scalefont setfont" ^
-c "(comic.ttf) show showpage"
When I do this, I see:
gswin32c.exe ^
-o comic-ttf.pdf ^
-sDEVICE=pdfwrite ^
-sFONTPATH=c:/windows/fonts ^
-dHaveTrueTypes=true ^
-g5950x8420 ^
-c "200 700 moveto" ^
-c "/ComicSansMS findfont 60 scalefont setfont" ^
-c "(comic.ttf) show showpage"
GPL Ghostscript 9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Scanning c:/windows/fonts for fonts... 423 files, 255 scanned, 240 new fonts.
Loading ComicSansMS font from c:/windows/fonts/comic.ttf... 3343720 1813337 2926116 1611207 1 done.
and my output PDF comic-ttf.pdf looks OK and does have the comic.ttf font embedded.
If this does also work for you, then your Ghostscript and your comic.ttf are OK, but your PDF file cards-01.pdf is not.

I came back to this problem after a delay. Upon further investigation with a magnifying glass, the problem is different from what I initially thought.
Text is definitely being rendered incorrectly in parts of the document. Each letter is far too small, though the spacing is oddly correct. However, the individual letters are the correct shape for the font.
The font on disk is not being accessed, but that's because the fonts are all embedded within the document. This fact would probably have been obvious to a Ghostscript expert from the output I posted in the original question (I'm guessing the "HYLUQF+" prefix is the smoking gun there), but I don't work with Ghostscript much. My fonts were installed correctly, and other documents were able to access them without trouble.
Of course, this still leaves the question of why my embedded fonts are being rendered incorrectly, but I will investigate that separately and/or post a different question. I maintain that the PDF file is uncorrupted (I have several other PDFs which exhibit the same problem), but I still don't know what's wrong.
#pipitas: Thanks very much for trying. You certainly did help verify that my installed fonts are not the problem. Actually, now that I look again, you even gently suggested the font might be embedded, but I either didn't see it, didn't believe it, or didn't know how to check.

Related

Ghostscript not prining accented characters correctly

I have a Bash script that writes a text watermark to PDF files. It does this by generating an overlay PDF with Ghostscript and then using PDFtk to stamp the overlay onto the original.
All this works perfectly, except that Ghostscript is not writing accented characters correctly. If my input text is, for example, "Français", the output on the PDF will be "Franˆ§ais".
My Ghostscript command line is:
/usr/local/bin/gs -q -o "${TEMPFILE}" \
-sDEVICE=pdfwrite -sPAPERSIZE=letter \
-c "60 23 moveto 0.32 0.23 0.22 setrgbcolor /Helvetica-Oblique findfont 9 scalefont setfont (${WATERMARK}) show"
The $WATERMARK variable contains a single line of text to be written. The problem occurs both when running the Bash script that contains this line and also when I run just this command directly.
I'm seeing this problem using Ghostscript 9.06 on Mac OS X (installed via Homebrew) and 9.05 on Ubuntu 12.04 (installed from the Ubuntu package repository). The Bash script and gs command line were both written by someone else; I have no experience using Ghostscript myself.
Changing the font has no effect on the problem and I've been unable to google anything useful related to this. What are we doing wrong here?
Thanks.
You haven't encoded the font correctly (or indeed at all).
You are assuming that the character code which represents the glyph named ccedilla is the same in the font as it is on your computer system. For Latin fonts, and the ASCII characters up to 127 this is usually true, for characters beyond that it usually isn't and for non-Latin languages (eg Russian, Arabic, CJKV languages, etc) it isn't true at all.
Encoding fonts isn't hard, but it is rather lengthy to go into here, so instead let me recommend the excellent series of articles written by John Deubert of Acumen Training, you can find them here:
http://www.acumentraining.com/acumenjournal.html
For your purposes I suggest the November and December 2001 articles.

How should I setup MATLAB for correct display of Russian (Cyrillic) characters on figures in Linux?

I have installed MATLAB R2008b on Ubuntu 12.04.4 LTS and Windows XP.
The system locale in Ubuntu is Unicode - en_US.UTF-8.
For compatibility with Windows I launch MATLAB in Ubuntu with ru_RU.CP1251 locale - so I have simple script to launch MATLAB:
cat /opt/MATLAB_R2008b/bin/matlab-run
#!/bin/bash
export LANG="ru_RU.CP1251";
export LC_ALL="ru_RU.CP1251";
/opt/MATLAB_R2008b/bin/matlab -desktop
After that slCharacterEncoding and feature('DefaultCharacterSet') returns desired windows-1251 as expected.
There are many fonts in my system, almost all support Russian (Cyrillic) glyphs.
Russian text displays normally in uicontrol (see screenshot )
uicontrol('String','Русский=Russian','Position',[0 0 200 200])
but does not in figure labels and title, so
x = linspace(0,2*pi,100); y = sin(x);
xlabel('x, в радианах','interpreter','none');
ylabel('y, значение sin(x)','interpreter','none');
title('y, значение sin(x)','interpreter','none');
produce wrong characters in labels and title .
I have no idea how to fix this.
How should I setup MATLAB for correct display of Russian (Cyrillic) characters on figures in Linux?
I solved my problem.
I installed all recommended fonts - packages xfonts-100dpi, xfonts-75dpi, xfonts-cyrillic, t1-cyrillic, cm-super, ttf-freefont, gsfonts-x11.
But what is interesting these fonts work only for UTF-8, so I can use the following fonts for displaying Russian (Cyrillic) text in figures:
clean
free avant garde
free bookman
free chancery
free courier
free helvetian
free paladin
free schoolbook
free times
oldslavic
tahoma guap
teams
terminus
For my original problem I found special ttf-font file, which works as expected and Russian (Cyrillic) text looks as expected in CP/Windows-1251 charset.
I placed this font in /usr/local/share/fonts/truetype, ran mkfontscale, mkfontdir and fc-cache -vf and added this location to /etc/X11/xorg.conf:
Section "Files"
FontPath "/usr/share/fonts/truetype"
FontPath "/usr/local/share/fonts/truetype"
EndSection
.
I installed language-pack-ru and edited /var/lib/locales/supported.d/local as follows:
en_US.UTF-8 UTF-8
ru_RU ISO-8859-5
ru_RU.CP1251 CP1251
ru_RU.KOI8-R KOI8-R

eps files render badly

When I open or convert eps files created with gnuplot, some of the lines don't come out properly. I am using Debian squeeze. Strangely when I view them on a windows PC they look fine.
See attatched example
This was converted with the command:
gs -r400 -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=png16m -sOutputFile=output.png -dBATCH -dNOPAUSE input.eps
the results are the same when viewed on the screen. Notice on the aerofoil lower surface, some of the line segments are actually triangles.
Thanks

Ghostscript under linux: Times too wide

How to make Times working for printing under linux?
I have debian wheezy linux, ghostscript, cups, mscorefonts installed.
But when i do print, i get Times too wide, comparing to windows one -- letter spacing are too wide.
Any way to fix that problem?
Printing done from same Java applet and on Win and on Lin.
Postscript from Lin variant use Times fonts, postscript from Win variant uses TimesNewRomanPSMT font.
Just replacement font name changes it, but not changes anything in output.
=================
Debian Wheezy, Debian Squeeze, Ubuntu Natty checked as linux.
Most of checks was in Debian Wheezy.
ghostscript:
Installed: 9.02~dfsg-2
sun-java6-jre:
Installed: 6.26-1
cups-pdf printer.
PPD is PDF.ppd:
*PCFileName: "CUPS-PDF.PPD"
*Manufacturer: "Generic"
*Product: "(CUPS v1.1)"
*ModelName: "Generic CUPS-PDF Printer"
*ShortNickName: "Generic CUPS-PDF Printer"
*NickName: "Generic CUPS-PDF Printer"
*1284DeviceID: "MFG:Generic;MDL:CUPS-PDF Printer;DES:Generic CUPS-PDF Printer;CLS:PRINTER;CMD:POSTSCRIPT;"
Print result Comparsion: http://piccy.info/code2/1652248/4b2c3b10f5316f9836496af5501892d1/
I DO have Times New Roman font on linux system! PDF for windows was generated on linux with linux ghostscript from postscript source generated on windows machine.
For example, take a look into right upper corner, where 0401060 written.
Windows postscript code:
%%IncludeResource: font TimesNewRomanPS-BoldMT
F /F1 0 /256 T /TimesNewRomanPS-BoldMT mF
/F1S53 F1 [83 0 0 -83 0 0 ] mFS
F1S53 Ji
4292 333 M (0401060)[42 42 42 42 42 42 0]xS
N 367 367 M 1192 367 I K
N 1667 367 M 2492 367 I K
51282 VM?
linux postscript code:
10.0 29 F
<303430313036> 37.44 526.0 52.0 S
10.0 29 F
<30> 6.24 541.0 62.0 S
N
as you can see, it selects font #29 of size 10.0. Font #29 is
/Times-Bold ISOF
and, worst thing, it already writes two lines -- so problem are somewhere in java<=>cups connector.
==================
"Same Java Applet" is internet-bank application iBank2.
"Times" is substituted by Ghostscript to Nimbus, not to TimesNewRoman:
./Init/Fontmap.GS:/Times-Roman /NimbusRomNo9L-Regu ;
./Init/Fontmap.GS:/Times-Italic /NimbusRomNo9L-ReguItal ;
./Init/Fontmap.GS:/Times-Bold /NimbusRomNo9L-Medi ;
./Init/Fontmap.GS:/Times-BoldItalic /NimbusRomNo9L-MediItal ;
./Init/Fontmap.GS:/TimesNewRoman /TimesNewRomanPSMT ;
./Init/Fontmap.GS:/TimesNewRoman,Bold /TimesNewRomanPS-BoldMT ;
./Init/Fontmap.GS:/TimesNewRoman,Italic /TimesNewRomanPS-ItalicMT ;
./Init/Fontmap.GS:/TimesNewRoman,BoldItalic /TimesNewRomanPS-BoldItalicMT ;
(BTW, are you using Ghostscript on Windows at all, or is your printing there going through a native printer driver?)
On windows i'm print onto PostScript native driver to .ps file.
So it is NOT a Ghostscript problem per se... but it maybe originating from different Java versions + configurations on your Win/Lin systems.
It looks like problem in java on printing, but that doesn't depends on java version -- both have latest java6 installed.
That PostScript most likely generated by your Java applet, and Ghostscript is only the consumer of it when it goes through the printing process.
Normally, i just want to make sure it uses TimesNewRoman font for Times one, not Nimbus.
And i have failed to make this.
ISOF macro generated by printing is:
/ISOF {
dup findfont dup length 1 add dict begin {
1 index /FID eq {pop pop} {D} ifelse
} forall /Encoding ISOLatin1Encoding D
currentdict end definefont
} BD
Here is cut of start files, and generated resulting PDF: http://datacompboy.ru/u/smpl.tar.bz2
If this is so, then copy the Windows fontfile to Linux.
it are already copy of windows file. msttcorefonts are identical to one, distributed with windows.
Since in generated postscript file already 0401060 split to two lines, that means, that java applet are while printing found that font too wide, and split upon generating... So question is -- how to substitute Times font in system so, that java printing will find TimesNewRoman instead of Nimbus, and generate correct output?
From what I see in the screenshot, your Win <--> Lin printing differences...
...do NOT originate in Times <--> TimesNewRomanPSMT differences,
...but rather come from [SomeTimes] <--> [SomeTimesBold] differences in the 2 PostScript output(s)
that is consumed by each printer queue (which on Linux very likely involves a Ghostscript installation). (BTW, are you using Ghostscript on Windows at all, or is your printing there going through a native printer driver?)
So it is NOT a Ghostscript problem per se... but it maybe originating from different Java versions + configurations on your Win/Lin systems.
The fact that your Linux PostScript code seems to make use of the /Times-Bold (ISOF????) font is outside of Ghostscript's responsibility. That PostScript most likely generated by your Java applet, and Ghostscript is only the consumer of it when it goes through the printing process.
It looks to me that this ominous ISOF you mentioned is not part of the fontname, but a PostScript procedure that must be pre-defined elsewhere in the PostScript file and is applied to the /Times-Bold font. It is probably a procedure which re-encodes the original font to ISOLatin1Encoding...
You say you have access to both font files (TimesNewRomanPS-BoldMT on Windows and Times-Bold on Linux). If this is so, then copy the Windows fontfile to Linux. Then, to verify the visual differences between the two fonts, run these two commands on each of the fontfiles:
fntsample \
-f /path/to/Times-fontfile.suffix \
-o Times-fontfile.suffix.pdf \
-l \
> Times-fontfile.suffix.txt
and then
pdfoutline \
Times-fontfile.suffix.pdf \
Times-fontfile.suffix.txt \
Times-fontfile-sample.pdf
The resulting PDF(s), Times-fontfile-sample.pdf, will represent a tabular sample of each glyph contained in the fontfiles, and these will be mapped to the respective Unicode codepoints sections.
You can use these PDFs to reveal even minimal visual discrepancies between the two fonts (but I bet your differences will be rather glaring).
In case you don't have installed pdfoutline and fntsample in your Debian, just run sudo apt-get install fntsample...
Update 2 (taking into account the updated problem description):
datacompboy has now provided a tarball containing these 4 files:
-rw-r--r-- datacompboy/datacompboy 37722 2011-06-22 08:54 smpl/linout.ps
-rw-r--r-- datacompboy/datacompboy 15324 2011-06-22 08:54 smpl/linout.pdf
-rw-r--r-- datacompboy/datacompboy 54422 2011-06-22 08:57 smpl/winout.pdf
-rw-r--r-- datacompboy/datacompboy 99099 2011-06-22 08:56 smpl/winout.ps
With these files, it should be very easy to pinpoint the cause of the problem. If datacompboy can run the Windows-generated PS file on a Linux Ghostscript, like this:
gs winout.ps
and if it renders OK (i.e.: the same as winout.pdf), then there is no problem with the GS font mapping, but a problem with the actual file differences in winout/linout.ps. From there, it should be quite easy to continue the analysis.
Unfortunately, right now I cannot run the test myself.
Update 3:
datacompboy's PDF files linout.pdf and winout.pdf have one huge difference: the Linux version doesn't have the font embedded, while the Windows one has... The consequence is that any posterior consumer of linout.pdf will produce fairly arbitrary results when displaying, printing, converting or processing this file with regard to the font.
So here is another test that I can think of. It checks how much the Linux versions of the fonts used for /Times-Bold (which is substituted by Ghostscript with the real /NimbusRomNo9L-Medi) and /TimesNewRomanPS-BoldMT` do differ in their font metrics.
Create three different PDFs with these Ghostscript commandlines:
a.pdf:
gs \
-o a.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-c "100 700 moveto \
/TimesNewRoman,Bold findfont \
12 scalefont \
setfont \
(0401060 0401060 0401060 0401060) show \
showpage"
b.pdf:
gs \
-o b.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-c "100 700 moveto \
/TimesNewRomanPS-BoldMT findfont \
12 scalefont \
setfont \
(0401060 0401060 0401060 0401060) show \
showpage"
c.pdf:
gs \
-o c.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-c "100 700 moveto \
/Times-Bold findfont \
12 scalefont \
setfont \
(0401060 0401060 0401060 0401060) show \
showpage"
The -dPDFSETTINGS=/prepress parameter should enforce the font embedding into output PDFs. (This is important, otherwise the viewer could use an arbitrary replacement font for displaying the PDF.)
What follows the -c parameter is a little PostScript snippet that provides content for the PDF page.
Files 'a.pdf' and 'b.pdf' should not differ. They only test if the font aliasing between /TimesNewRoman,Bold and /TimesNewRomanPS-BoldMT do indeed work as expectd.
File 'c.pdf' could show slight differences in comparison to a.pdf and b.pdf in the order of a few pixel here and there, but NOT in the tracking of the tested string.
If this test goes as predicted, the different fontfiles, the Fontmap.GS and Ghostscript itself all are OK. Then the problem is only with the way the Linux Java applet produces its output (PS or PDF).

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

So I'd like to add a "footer" (an attribution) to the bottom of every page of a pdf file I am generating via postscript with groff in linux. I am converting the file from ps to pdf myself, with the ps2pdf tool, so I have access to both formats.
These two posts have been somewhat helpful:
How to add page numbers to Postscript/PDF
How can I make a program overlay text on a postscript file?
I'm not against using the first method, but I don't have access to the pdflatex utility mentioned in the first script, nor do I have the option to install it on the machine that needs to do the work.
It looks like the second method could possibly work, but I have version 8.15 of ghostscript installed and I didn't see many of the flags listed on the man page ( http://unix.browserdebug.com/man/gs/ ). I think I have access to the "-c" flag to insert some postscript code, even though it is not listed. Anyhow, here are two commands I tried unsuccessfully:
gs -o output.pdf -sDEVICE=pdfwrite -g5030x5320 \
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (test-string) show" \
-f input.ps
that gives me this:
Unknown switch -o - ignoring
ESP Ghostscript 815.02 (2006-04-19)
Copyright (C) 2004 artofcode LLC, Benicia, CA. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
ERROR: /undefinedfilename in (output.pdf)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1117/1686(ro)(G)-- --dict:0/20(G)-- --dict:102/200(L)--
Current allocation mode is local
Last OS error: 2
ESP Ghostscript 815.02: Unrecoverable error, exit code 1
So obviously the -o flag has a problem and so I did some research and tried this syntax:
gs -sOUTPUTFILE=output.pdf -sDEVICE=pdfwrite -g5030x5320 \
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (test-string) show" \
-f input.ps
which outputs this and makes me hit return 4 times (maybe there are 4 pages in input.ps)
ESP Ghostscript 815.02 (2006-04-19)
Copyright (C) 2004 artofcode LLC, Benicia, CA. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Can't find (or can't open) font file /usr/share/ghostscript/8.15/Resource/Font/Helvetica-Italic.
Can't find (or can't open) font file Helvetica-Italic.
Querying operating system for font files...
Didn't find this font on the system!
Substituting font Helvetica-Oblique for Helvetica-Italic.
Loading NimbusSanL-ReguItal font from /usr/share/fonts/default/Type1/n019023l.pfb... 3742416 2168114 2083056 759694 1 done.
Loading NimbusRomNo9L-ReguItal font from /usr/share/fonts/default/Type1/n021023l.pfb... 3781760 2362033 2365632 1015713 1 done.
Loading NimbusRomNo9L-Medi font from /usr/share/fonts/default/Type1/n021004l.pfb... 3865136 2547267 2365632 1029818 1 done.
Loading NimbusRomNo9L-Regu font from /usr/share/fonts/default/Type1/n021003l.pfb... 4089592 2759001 2365632 1032885 1 done.
Using NimbusRomanNo9L-Regu font for NimbusRomNo9L-Regu.
>>showpage, press <return> to continue<<
>>showpage, press <return> to continue<<
>>showpage, press <return> to continue<<
>>showpage, press <return> to continue<<
So it seems like it would be simple enough to use gs to simply insert something in a ps file, but it is proving to be quite complicated...
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=out.pdf. 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
The most logical place to add page footers is in the groff source. The exact way to do this will of course depend on the macro package youre using. For -ms, you can do:
.ds RF "Page \\n(PN
to add the page number as right footer. For -mm, it's more like:
.PF "'''Page \\\\nP'"
where the single quotes delimit the 'left part'center part'right part' of the footer.

Resources