5

Its superconfusing for me, since pdfmaker and postscript are doing same, but in practice coding style is quite different.

I know how to make a line with 2 circles at its end, with moveto and lineto and arc command in Postscript language, however, apparently I have to move to pdfmark due to hyperlinks, pdfmark manual is super un-understandable, and there is no other reference(book/online tutorial).

So, I would be appreciate, if one could generate such thing (as my figure shows) with a little description.

enter image description here

Areza
  • 5,623
  • 7
  • 48
  • 79

1 Answers1

6

Here's the most simplest version possible. This creates a clickable area in the bottom left corner of the PDF that goes off to a 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

By default a border will be drawn so you might want to clear that out:

[/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

This only creates a clickable area, however. You then need to draw some text to click on:

/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

Lastly, pdfmark isn't technically defined within the standard so they recommend that if you're not using Adobe's Distiller that you define something to handle it. This code will basically just ignore pdfmark if the compiler doesn't recognize it:

/pdfmark where
  {pop}
  {
  /globaldict where
    { pop globaldict }
    { userdict }
  ifelse
   /pdfmark /cleartomark load put
  }
 ifelse

And here's a full working PostScript program:

%!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

EDIT

Also, check out this manual for more in-depth instructions on pdfmark

EDIT 2

Also, also, I should point out that I've spaced things out for instructional purposes. In most cases you'll see the /Action written as a single line such as:

/Action << /Subtype /URI /URI (http://www.example.com/) >>
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • I made pdf out of ps by using ps2pdf, and the output is not the thing we expect to see :( no shape, no line ... just www.example.com in left bottom cornet !! – Areza Aug 29 '11 at 09:09
  • @user702846, what I posted was how to add a hyperlink to a PDF since you said you already knew how to do the rest. Hyperlinks basically sit on top of content that you're already created, not within. So create your shapes and text exactly as you did before and then use this code to add a hyperlink on top of it. – Chris Haas Aug 29 '11 at 12:53