如何在Linux中的postscript或pdf文件的每个页面的底部添加页脚?
所以我想添加一个“footer”(归属)到我通过postscript与groff在linux中生成的pdf文件的每一页的底部。我使用ps2pdf工具将文件从ps转换为pdf,因此我可以访问这两种格式。如何在Linux中的postscript或pdf文件的每个页面的底部添加页脚?
这两个职位已经有点帮助:
How to add page numbers to Postscript/PDF
How can I make a program overlay text on a postscript file?
我不反对使用第一种方法,但我没有获得在提到pdflatex
工具第一个脚本,我也没有选择将它安装在需要完成工作的机器上。
它看起来像第二种方法可能工作,但我已安装ghostscript版本8.15,我没有看到手册页上列出的许多标志(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文件的东西,但它被证明是相当复杂的...
ESP Ghostscript的是O-O-O-O-老。除非你绝对,绝对不能避免它,否则不要再使用它。这是CUPS使用的原始Ghostscript的一个分支。 (并在开发者之间的一些问题,其中解决了,更近的CUPS现在还再次使用GPL Ghostscript的版本...)
较新的GPL的Ghostscript版本在这里:http://www.ghostscript.com/releases/
此外,-o out.pdf
只是一个速记-dBATCH -dNOPAUSE -sOutputFile=outpdf
。所以你应该试试这个。 (-dNOPAUSE
部分免除您每页前进的<return>
....)。
最后,不要指望由第三方man gs
页面提供的全部文档。而是指原Ghostscript的文档,您使用的版本,最重要的部分是:
-
当前开发分支: Readme.htm + Use.htm + Ps2pdf.htm - 9。00释放:Readme.htm + Use.htm + Ps2pdf.htm
- 8.71释放:Readme.htm + Use.htm + Ps2pdf.htm
更新: Ghostscript的已移动到GIT中(而不是颠覆),用于他们的源代码库。为此以下链接已经改变,反复:
-
当前开发分支: Readme.htm + Use.htm + Ps2pdf.htm - 当前开发分支:Readme.htm + Use.htm + Ps2pdf.htm
在你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
添加页脚的最合理的地方是在groff
源代码中。确切的做法当然取决于你使用的宏包。对于-ms
,你可以这样做:
.ds RF "Page \\n(PN
添加页码为右页脚。对于-mm
,它更像是:
.PF "'''Page \\\\nP'"
其中单引号界定之躯“左part'center part'right一部分”。
我正在使用ESP安装的系统,没有安装升级版本的权限。我想知道是否有办法让它与ESP一起工作... – cwd 2011-02-05 06:59:31
ESP Ghostscript不再维护....要使它成为非特权用户的唯一方法是另外安装更新的版本Ghostscript到您的主目录(或任何其他地方可由您的帐户写入)。 – 2011-02-12 11:04:55