2011-01-22 46 views
6

所以我想添加一個「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文件的東西,但它被證明是相當複雜的...

回答

5

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的文檔,您使用的版本,最重要的部分是:


更新: Ghostscript的已移動到GIT中(而不是顛覆),用於他們的源代碼庫。爲此以下鏈接已經改變,反覆:

+0

我正在使用ESP安裝的系統,沒有安裝升級版本的權限。我想知道是否有辦法讓它與ESP一起工作... – cwd 2011-02-05 06:59:31

+0

ESP Ghostscript不再維護....要使它成爲非特權用戶的唯一方法是另外安裝更新的版本Ghostscript到您的主目錄(或任何其他地方可由您的帳戶寫入)。 – 2011-02-12 11:04:55

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 
1

添加頁腳的最合理的地方是在groff源代碼中。確切的做法當然取決於你使用的宏包。對於-ms,你可以這樣做:

.ds RF "Page \\n(PN 

添加頁碼爲右頁腳。對於-mm,它更像是:

.PF "'''Page \\\\nP'" 

其中單引號界定之軀「左part'center part'right一部分」。