这是最简单的版本。这会在 PDF 的左下角创建一个指向 URL 的可点击区域。
[/Rect [ 0 0 200 200 ] % Draw a rectangle
/Action % Define an action
<<
/Subtype /URI % Define the action's subtype as a hyperlink
/URI (http://www.example.com/) % Set the URL
>>
/Subtype /Link % Set the type of this PDFmark to a link
/ANN pdfmark % Add the annotation
默认情况下会绘制一个边框,因此您可能需要清除它:
[/Rect [ 0 0 200 200 ] % Draw a rectangle
/Action % Define an action
<<
/Subtype /URI % Define the action's subtype as a hyperlink
/URI (http://www.example.com/) % Set the URL
>>
/Border [0 0 0] % Remove the border
/Subtype /Link % Set the type of this PDFmark to a link
/ANN pdfmark % Add the annotation
不过,这只会创建一个可点击区域。然后你需要绘制一些文本来点击:
/Helvetica findfont 16 scalefont setfont % Set the font to Helvetica 16pt
5 100 moveto % Set the drawing location
(http://www.example.com/) show % Show some text
最后,pdfmark 在技术上并未在标准中定义,因此他们建议如果您不使用 Adobe 的 Distiller,您可以定义一些东西来处理它。如果编译器无法识别,这段代码基本上会忽略pdfmark:
/pdfmark where
{pop}
{
/globaldict where
{ pop globaldict }
{ userdict }
ifelse
/pdfmark /cleartomark load put
}
ifelse
这是一个完整的 PostScript 程序:
%!PS-Adobe-1.0
/pdfmark where
{pop}
{
/globaldict where
{ pop globaldict }
{ userdict }
ifelse
/pdfmark /cleartomark load put
}
ifelse
[/Rect [ 0 0 200 200 ] % Draw a rectangle
/Action % Define an action
<<
/Subtype /URI % Define the action's subtype as a hyperlink
/URI (http://www.example.com/) % Set the URL
>>
/Border [0 0 0] % Remove the border
/Subtype /Link % Set the type of this PDFmark to a link
/ANN pdfmark % Add the annotation
/Helvetica findfont 16 scalefont setfont % Set the font to Helvetica 16pt
5 100 moveto % Set the drawing location
(http://www.example.com/) show % Show some text
showpage
编辑
另外,check out this manual 以获取有关 pdfmark 的更深入说明
编辑 2
此外,我还应该指出,出于教学目的,我已将内容隔开。在大多数情况下,您会看到 /Action 写成一行,例如:
/Action << /Subtype /URI /URI (http://www.example.com/) >>