如何在linux中的postscript或pdf文件的每一页底部添加页脚?

cwd*_*cwd 6 unix linux pdf postscript ghostscript

所以我想在pdf文件的每一页的底部添加一个"页脚"(一个属性),我通过linux中的groff通过postscript生成.我正在使用ps2pdf工具将文件从ps转换为pdf,因此我可以访问这两种格式.

这两个帖子有点帮助:

如何将页码添加到Postscript/PDF

如何在postscript文件上创建程序覆盖文本?

我并不反对使用第一种方法,但我无法访问pdflatex第一个脚本中提到的实用程序,也无法在需要执行此操作的计算机上安装它.

看起来第二种方法可能会起作用,但我安装了版本8.15的ghostscript,并且我没有看到手册页上列出的许多标志(http://unix.browserdebug.com/man/gs/).我想我可以访问"-c"标志来插入一些postscript代码,即使它没有列出.无论如何,这是我尝试过的两个命令:

gs -o output.pdf -sDEVICE=pdfwrite -g5030x5320 \
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (test-string) show" \
-f input.ps

这给了我这个:

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

所以很明显-o标志有问题所以我做了一些研究并尝试了这种语法:


gs -sOUTPUTFILE=output.pdf -sDEVICE=pdfwrite -g5030x5320 \
-c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (test-string) show" \
-f input.ps

输出这个并让我回击4次(也许在input.ps中有4页)


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


因此,使用简单的方法gs来简单地在ps文件中插入内容似乎很简单,但事实证明它非常复杂......

Shm*_*ken 6

在PostScript文件中,您可以使用页面计数器并重新定义showpage以在页脚中显示它.这是一个示例程序:

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
Run Code Online (Sandbox Code Playgroud)


Kur*_*fle 5

ESP Ghostscript是Oooo-old.不要再使用它,除非绝对,绝对无法避免.它是原始Ghostscript的一个分支,CUPS使用了一段时间.(并且在解决了开发人员之间的一些问题后,更新版本的CUPS现在也再次使用GPL Ghostscript ......)

较新的GPL Ghostscript版本在这里:http://www.ghostscript.com/releases/

此外,-o out.pdf只是一个简写-dBATCH -dNOPAUSE -sOutputFile=outpdf.所以你应该试试这个.(这-dNOPAUSE部分让你免于<return>每次页面前进......).

最后,不要指望第三方 man gs页面提供全部文档.而是参考您使用的版本的原始Ghostscript文档,最重要的部分是:


更新: Ghostscript已将其源代码存储库移至Git(而非Subversion).因此,以下链接反复更改: