[pdftex] embedfile and links to children
Heiko Oberdiek
oberdiek at uni-freiburg.de
Fri Nov 3 11:18:20 CET 2006
On Fri, Nov 03, 2006 at 09:13:23AM +0100, Victor Ivrii wrote:
> The source below makes foo.pdf with attached (produced separately)
> yellow.pdf and with the link from
>
> "Yellow Page 3" in foo.pdf to Page 3 of its yellow child.
>
>
> Now, if I replace \attachfile{yellow.pdf} by embedfile{yellow.pdf}
> link stops working. Am I missing something?
Yes, the embedded file is addressed differently by the
/N key in the dictionary /T.
> % foo.tex
> \documentclass{article}
> \usepackage{hyperref}
> \usepackage{attachfile2}
> \usepackage{embedfile}
>
> \begin{document}
>
> \attachfile{yellow.pdf} % file annotation is on page 1
% Use key annotname to address the annotation properly
\attachfile[annotname={yellow}]{yellow.pdf}
> \leavevmode
> \pdfstartlink user{%
> /Subtype/Link
> /A<<
> /S/GoToE
> /D [2 /FitH 1000] % page 3
> /T<<
> /R/C % the target file is the embedded file (child),
> % see PDF specification for more complicate
> % relationships
> % Currently attachfile and attachfile2 do not support embedded
> % files that are not referenced by a file annotation, therefore
> % the addressing scheme for file annotations is used:
attachfile and attachfile2 attach files to a page with
a file attachment annotation, package embedfile attaches
files to the document, there isn't a annotation in this case.
> /P 0 % page that contains the file annotation, zero based index
You can use package zref, modul abspage for referencing the absolute
page number, see example below.
> % attachfile does not support named file annotations, thus you
> % have to use the zero based index in the Annots array
> % (probably this is not trivial to know, if there are more than one
> % annotation).
This is the problem, you don't know the number of the index in
the Annots array, but you can use annotname of attachfile2 for
addressing the annotation:
/A(yellow)
% /A 0 % zero based index in the Annots array,
> % /A 1 %%%%%% if secondattachment.pdf is referenced
> % /A(foo) % this is the value of option annotname
> % of \attachfile, see above,
> % requires attachfile2
ok.
In case of embedded files, there isn't a annotation, thus
you use the key in the EmbeddedFiles name tree that happens to
be the file name (package embedfile), see example below.
> >>
> >>
> }\relax
> Yellow Page 3\pdfendlink
>
> \end{document}
Example:
\documentclass{article}
\usepackage{attachfile2}
\usepackage{embedfile}
\usepackage{zref-abspage}
\usepackage{hyperref}
\makeatletter
\zref at newprop{annotname}{%
\expandafter\expandafter\expandafter\@gobble
\expandafter\@gobbletwo\atfi at annotname
}
\zref at newlist{GoToE}
\zref at addprop{GoToE}{abspage}
\zref at addprop{GoToE}{annotname}
\define at key{AtFi}{zlabel}{%
\zref at labelbylist{#1}{GoToE}%
}
\providecommand*{\@gotoecolor}{\@filecolor}
\providecommand*{\@gotoebordercolor}{\@filebordercolor}
\define at key{Hyp}{gotoecolor}{\def\@gotoecolor{#1}}
\define at key{Hyp}{gotoebordercolor}{%
\Hy at bordercolor{gotoe}{#1}{ }%
}
\newcommand*{\gotoelinkattach}[3]{% zlabel name, page, anchor text
\begingroup
\leavevmode
\pdfstartlink
attr{%
\Hy at setpdfborder
/H\@pdfhighlight
/C[\@gotoebordercolor]%
}%
user {%
/Subtype/Link
/A<<%
/S/GoToE%
\ifHy at newwindow /NewWindow true\fi
/D[\the\numexpr#2-1\relax/XYZ null null null]%
/T<<%
/R/C%
/P \the\numexpr\zref at extractdefault{#1}{abspage}{1}-1\relax
/A\zref at extractdefault{#1}{annotname}{()}%
>>%
>>%
}%
\relax
\Hy at colorlink\@gotoecolor#3%
\close at pdflink
\endgroup
}
\newcommand*{\gotoelinkembed}[3]{% file name, page, anchor text
\begingroup
\leavevmode
\pdfstartlink
attr{%
\Hy at setpdfborder
/H\@pdfhighlight
/C[\@gotoebordercolor]%
}%
user {%
/Subtype/Link
/A<<%
/S/GoToE%
\ifHy at newwindow /NewWindow true\fi
/D[\the\numexpr#2-1\relax/XYZ null null null]%
/T<<%
/R/C%
/N<\pdfescapehex{#1}>%
>>%
>>%
}%
\relax
\Hy at colorlink\@gotoecolor#3%
\close at pdflink
\endgroup
}
\makeatother
\begin{document}
\tableofcontents
\newpage
\section{Test A}
\gotoelinkattach{dummyB}{2}{Zu Seite 2 (dummy3.pdf attached)},
\gotoelinkembed{foobar3.pdf}{2}{Zu Seite 2 (foobar3.pdf embedded)}
\newpage
\section{Test B}
% annotname must be given first to be recognized by zlabel
\attachfile[annotname={dummyA},zlabel={dummyB}]{dummy3.pdf}
\embedfile{foobar3.pdf}
\end{document}
Yours sincerely
Heiko <oberdiek at uni-freiburg.de>
--
More information about the pdftex
mailing list