Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple line with two hyperlinks at end in postscript and pdfmaker

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

like image 607
Areza Avatar asked Aug 13 '11 14:08

Areza


1 Answers

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/) >>
like image 88
Chris Haas Avatar answered Sep 23 '22 06:09

Chris Haas