2011-01-11 143 views
2

基本上我试图通过修改postscript来将超链接添加到PDF中。使用PostScript创建PDF超链接

下面是Adobe提供的用于通过PostScript生成的链接代码:

[/Rect [ 0 425 295 445 ] /Action << /Subtype /URI /URI (http://www.adobe.com/) >> /Border [ 0 0 2 ] /Color [ .7 0 0 ] /Subtype /Link ANN pdfmark

而这里的代码我试图修改的一个例子:

%PDF-1.4 
%âãÏÓ 
6 0 obj 
>stream 
    1 w 
    [] 0 d 
    0.0 g 
    36 775 m 
    576 775 l 
    s 
endstream 
endobj 
7 0 obj 
>stream 
    BT 
    36 777 Td 
    0 Tr 
    /F1 16 Tf 
    0.0 g 
    (Test PDF) Tj 
    ET 
endstream 
endobj 
1 0 obj 
>/ProcSet[/PDF]>>/Parent 8 0 R/MediaBox[0 0 612 792]/Contents[6 0 R 7 0 R]/Type/Page>> 
endobj 

9 0 obj 
>/ProcSet[/PDF]>>/Parent 8 0 R/MediaBox[0 0 612 792]/Contents[10 0 R 11 0 R]/Type/Page>> 
endobj 
8 0 obj 
> 
endobj 
12 0 obj 
> 
endobj 
13 0 obj 
> 
endobj 
xref 
0 14 
0000000000 65535 f 
0000017066 00000 n 
0000000015 00000 n 
0000000116 00000 n 
0000000212 00000 n 
0000000319 00000 n 
0000000422 00000 n 
0000003831 00000 n 
0000025138 00000 n 
0000024976 00000 n 
0000017226 00000 n 
0000021450 00000 n 
0000025207 00000 n 
0000025253 00000 n 
trailer 
]>> 
startxref 
25381 
%%EOF
+1

你在这里试图修改的是** NOT ** PostScript代码。它是PDF。 (是的,您可以将代码添加到PostScript中,以便在生成的PDF中具有超链接。此处的关键字是* pdfmark * ...) – 2011-01-12 22:24:14

回答

6

这里是你没有问一个建议,但仍可帮助你实现你的目标:使用Ghostscript转换您的PDF并添加超链接。

以下是操作方法。示例假定您使用Windows。在Linux或Mac OS X,使用gs(而不是gswin32c.exe和使用\作为续行,而不是^

gswin32c.exe^
    -o with-hyperlink.pdf^
    -sDEVICE=pdfwrite^
    -c "[ /Rect [0 425 295 465]"^
    -c " /Border [0 0 2]"^
    -c " /Color [.7 0 0]"^
    -c " /Page 1"^
    -c " /Action <</Subtype /URI"^
    -c " /URI (http://stackoverflow.com/questions/4663409/creating-a-pdf-hyperlink-with-postscript/4674664#4674664)>>"^
    -c " /Subtype /Link"^
    -c " /ANN pdfmark"^
    -f without-hyperlink.pdf 

此命令重新提炼原始PDF,没有-hyperlink.pdf,到与-hyperlink.pdf。生成的PDF将在第1页上有超链接。

虽然在文本编辑器中操作PDF的内容是可能的,但是太麻烦了,但是您需要成为一名真正的PDF专家为大多数PDF文件做到这一点