gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:44:00 24 4
gpt4 key购买 nike

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

这两个帖子有些帮助:

How to add page numbers to Postscript/PDF

How can I make a program overlay text on a postscript file?

我不反对使用第一种方法,但我无权访问第一个脚本中提到的 pdflatex 实用程序,也无法选择将其安装在需要的机器上需要做的工作。

看起来第二种方法可能可行,但我安装了 8.15 版的 ghostscript,但我没有看到手册页 (http://unix.browserdebug.com/man/gs/) 上列出的许多标志。我想我可以使用“-c”标志来插入一些后记代码,即使它没有列出。无论如何,这是我尝试失败的两个命令:

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 - ignoringESP 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_pushDictionary stack:   --dict:1117/1686(ro)(G)--   --dict:0/20(G)--   --dict:102/200(L)--Current allocation mode is localLast OS error: 2ESP 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 文件中简单地插入一些东西似乎很简单,但事实证明它非常复杂......

最佳答案

在您的 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

关于linux - 如何在 linux 中的 postscript 或 pdf 文件的每一页底部添加页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4766755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com