ghostscript header 在 pdf 文件上

ghostscript header over pdf file

想使用 ghostscript 在 pdf 文件上编写 header。我尝试了这个论坛的几个帖子

can I use Ghostscript to overlay a text (fax) header onto a PDF and/or TIFF?

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

我试过这段代码,它有效。我看不到 header,但是当我使用查找功能搜索 header 时,我可以在某处看到 header,但它不可见。

gs \
 -o /5/7007.pdf \
 -sDEVICE=pdfwrite \
 -g5030x5320 \
 -c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (544) show" \
 -f /5/77.pdf

其他代码为

gs -dBATCH  -dNOPAUSE  -sDEVICE=pdfwrite \
-sOutputFile=/5/7007.pdf \
-c "/Times findfont 12 scalefont setfont 50 765 moveto (header text) show" \
-f /5/77.pdf

这两个代码都生成 pdf 文件并且 header 也但是 header 不可见。

我的 ghostscript 输出是

Page 2
Page 3
Page 4
Page 5
Can't find (or can't open) font file %rom%Resource/Font/Arial-ItalicMT.
Can't find (or can't open) font file Arial-ItalicMT.
Can't find (or can't open) font file %rom%Resource/Font/Arial-ItalicMT.
Can't find (or can't open) font file Arial-ItalicMT.
Didn't find this font on the system!
Substituting font Helvetica-Oblique for Arial-ItalicMT.
Page 6
Page 7
Page 8
Page 9
Page 10
Page 11

我想在所有页面上写 header 和页脚,我可以使用任何字体,或者如果可能的话可以更改

。我使用 fc-list 列出了几种字体。我使用了其中一个然后也得到了类似的错误。似乎 ghostscript 正在尝试匹配每个页面 font.i 我对匹配每个页面的字体不感兴趣。只想为 header 使用一些可用的字体。

部分字体列表在这里

fc-list
Liberation Mono:style=Regular
Utopia:style=Bold Italic
Nimbus Sans L:style=Regular Italic
DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book
Hershey\-Gothic\-English:style=Regular
URW Palladio L:style=Roman
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic
Century Schoolbook L:style=Bold Italic
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold,Bold
Liberation Sans:style=Regular
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
DejaVu Sans Mono:style=Bold Oblique
Carlito:style=Italic
Liberation Serif:style=Bold Italic
Caladea:style=Bold
DejaVu Serif:style=Bold Italic
Nimbus Sans L:style=Bold
OpenSymbol:style=Regular
Utopia:style=Bold
Caladea:style=Bold Italic,Italic
Hershey\-Plain\-Duplex\-Italic:style=Regular

您需要添加在页面上做标记的代码作为EndPage 程序,否则您先在'page' 上做标记,然后写入PDF 文件的内容。我假设你想反过来做,先写 PDF 文件的内容,然后再写额外的内容。

您还应该设置文本的颜色,否则它会使用当前颜色,可能是白色。 0 setgray 0 0 0 setrgbcolor0 0 0 1 setcmykcolor 将当前颜色设置为黑色。

所以像这样:

-c "<</EndPage {0 setgray /Times 20 selectfont 453 482 moveto (544) show}>> setpagedevice" -f

应该可以正常工作。

关于 Arial-ItalicMT 的警告,这意味着您的 PDF 文件使用了该字体,但不包含它。您必须:

  1. 接受 Ghostscript (Helvetica-Oblique) 提供的替换
  2. 提供不同的替代品
  3. 提供真实字体

为了执行 2 或 3 中的任何一个,您需要修改 fontmap.GS 或 cidfmap,具体取决于它是缺少字体还是缺少 CIDFont。

添加更正后的代码:

-sDEVICE=pdfwrite -sOutputFile=\temp\out.pdf -c "<</EndPage {2 ne {0.5 setgray /Times 20 selectfont 453 48 moveto (Test) show pop true}{pop false} ifelse} >> setpagedevice" -f