[pdftex] Link annotations in included pdf documents

Lander lander at we.lc.ehu.es
Wed Feb 28 03:27:08 CET 2007


Dear List,

I'm afraid I didn't explain myself clear enough in my
previous message.  What I was trying to do is to make a
scanned book toc "clickable", that is, add some links to the
toc so that you can navigate to individual pages.

Thanh has kindly provided me with a couple of macros he had
used in the past to do what I wanted to.  Here you are (note
the use of <+place-holders+>):

    ====================================================================
    %%% In this approach we start at the upper left corner of the "text
    %%% area".  We need to move down to the desire coordinates and place
    %%% the annotation there.  (The calc package may help simplify the
    %%% calculational notation; not used here though.)
    
    \newdimen\dimenA
    \def\nullrule{\hrule height 0pt\relax}

    %% \putlink{x}{y}{width}{height}{linkname}
    \def\putlink#1#2#3#4#5{%
      \vbox to 0pt{
        \nullrule
        \dimenA=\paperheight
        
        % Compensate vertical margin: one inch + \voffset + \topmargin
        % \headheight + \headsep + \topmargin
        \advance\dimenA by -<+vmargin+>
        
        % y coordinate of the lower left corner of the link box; you can
        % get this one from gv or gsview.
        \advance\dimenA by -#2bp\relax
        
        \vskip\dimenA
        \nullrule
        \hbox to 0pt{%
          % x coordinate of the lower left corner of the link box; you
          % can get this one from gv or gsview.
          \hskip#1bp

          % Compensate horizontal margin: one inch + \hoffset
          % \oddsidemargin (or \evensidemargin + \marginparwidth
          % \marginparsep)
          \hskip -<+hmargin+>
          
          % The annotation itself, with <rule spec> (dimensions of the
          % box where the link is active)
          \pdfannot width #3 height #4 depth 0pt {%
            /Subtype /Link /C [1 0 0] /Dest (#5)}%
          \hss}%
        \vss
      }
      \nullrule
    }

    \def\putlinkstoTOC{%
      \putlink{<+xcoord+>}{<+ycoord+>}{<+width+>}{<+height+>}{<+dest+>}
      % More \putlink lines, if you wish
    }

    %% Contents page
    \includepdf[%
      page=<+contents_page+>, <+more_options+>,
      pagecommand={\thispagestyle{empty}\putlinkstoTOC}
    ]{<+book+>}
    ====================================================================


I don't feel very confortable with TeX primitives, and I
don't want to keep track of the vertical and horizontal
margin compensations.  I was working on a similar solution
to Thanh's, and thanks to him I've come up with another one,
which makes use of the eso-pic package
(\AddToShipoutPicture* command):

    ====================================================================
    %%% In this approach, we start at the lower left corner of the
    %%% "page".  We just need to give the coordinates of the point where
    %%% we want to place the link box.  No extra calculations needed.
    
    \newcommand{\putlink}[5]{%
      \bgroup
        \setlength{\unitlength}{1bp}
        \put(#1,#2){%
          \pdfannot width #3 height #4 depth 0pt
            {/Subtype /Link /C [1 0 0] /Dest (#5)}%
        }%
      \egroup
    }

    \newcommand{\putlinkstoTOC}{\AddToShipoutPicture*{%
      \putlink{<+xcoord+>}{<+ycoord+>}{<+width+>}{<+height+>}{<+dest+>}}
      % More \putlink lines, if you wish
    }
    ====================================================================


You can see a working example at 
    <http://www.divshare.com/download/170494-946>.

Cheers.
Lander

P. S.  I'm glad to see that we have a new version of xpdf.
Damn, it was precisely its lack of support for PDF 1.6 the
cause for these messages.  (Sigh...)


More information about the pdftex mailing list