开发者

Creating a PDF hyperlink with PostScript

Basically I'm trying to add a hyperlink into a PDF by modifying the postscript.

Here's the code that adobe provided for generating a link via 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

And here's an example of the code I'm trying to modify:

%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
e开发者_高级运维ndobj
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


Here is a suggestion which you didn't ask for, but which may nevertheless help you achieve your goal: Use Ghostscript to convert your PDFs and add the hyperlinks.

Here's how. Example assumes you use Windows. On Linux or Mac OS X, use gs (instead of gswin32c.exe and use \ as line continuation instead of ^:

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

This command re-distills the original PDF, without-hyperlink.pdf, into with-hyperlink.pdf. The resulting PDF will have the hyperlink on page 1.

It is possible, but much too cumbersome to manipulate the content of a PDF in a text editor. But you need to be a real PDF expert to do that for most PDFs.


Those ten digit numbers at the end are an index of the byte position within the file of each object. At a bare minimum, if you alter the contents of a PDF, you will need to correct that index.

The reference to the structure of a PDF document can be downloaded from Abdobe: http://www.adobe.com/devnet/pdf/pdf_reference.html


The answer can be found in the hint Kurt Pfeifle gave above. The 'pdfmark' feature for URLs seems to be a modern capability for PostScript to include live links if one uses a capable distiller to convert the PS to PDF. See the Adobe document at https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_pdfmark.pdf. I think the current 'ps2pdf' command should be able to handle it and will report my results after I check it out on my Debian host.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜