Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

unix - 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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...