[Tex/LaTex] XeLaTeX, \includegraphics and \hyperlink

graphicshyperreflinksxetex

I have question regarding XeLaTeX. I have switched from LaTeX to XeLaTeX because I wanted to use ttf fonts and now I have a problem with \hyperlink. It works with text, but it doesn't with images.

So for example, when I click on the text: Dit hjem, I will go to page 2. It does not work with image.

My code:

\documentclass[landscape,a4paper,11pt]{article} 
\special{papersize=297mm,210mm}

\usepackage{graphicx}
%\usepackage[pdftex]{graphicx}

\usepackage{hyperref}

\usepackage[danish]{babel}

\DeclareGraphicsExtensions{.png,.pdf,.jpg,.mps}

\usepackage[top=2cm, bottom=2cm, left=3cm, right=3cm]{geometry}
\usepackage[absolute]{textpos}
\pagestyle{empty}

\setlength{\parindent}{0pt}

\usepackage{color}

\hypersetup{
    bookmarks=true,         % show bookmarks bar?
    unicode=false,          % non-Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,        % show Acrobat’s toolbar?
    pdfmenubar=true,        % show Acrobat’s menu?
    pdffitwindow=false,     % window fit to page when opened
    pdfstartview={FitH},    % fits the width of the page to the window
    pdftitle={My title},    % title
    pdfauthor={Author},     % author
    pdfsubject={Subject},   % subject of the document
    pdfcreator={Creator},   % creator of the document
    pdfproducer={Producer}, % producer of the document
    pdfkeywords={keyword1} {key2} {key3}, % list of keywords
    pdfnewwindow=true,      % links in new window
    colorlinks=false,       % false: boxed links; true: colored links
    linkcolor=black,          % color of internal links
    citecolor=green,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=cyan,           % color of external links
    pdfnonfullscreenpagemode=true,
    linktoc=none,
    pdfborder={ 0 0 0}
}


\begin{document}

\hyperlink{page.2}{\includegraphics[height=14.869mm, width=14.869mm]{images/tiger}} 
\hyperlink{page.2}{\textblockcolour{white}{\fontsize{3mm}{5mm} \selectfont Dit hjem}}

\null\newpage
Some text

\end{document}

Best Answer

I was able to replicate your problem. I found a solution here: http://www.tug.org/pipermail/xetex/2005-October/002480.html

From the site:

You could possibly hack around this by wrapping your graphic
inclusion in a macro that outputs glyphs at two diagonally opposite
corners of the image; they could be small blank glyphs (e.g.,
\char32), so as not to show on the page, as long as they're real
glyphs in a font so that xdv2pdf "sees" them. I think that would
trick the driver into creating the proper link area.

Here's the command that does the work (again, from the site):

\newsavebox{\ximagebox}
\newlength{\ximageheight}
\newsavebox{\xglyphbox}
\newlength{\xglyphheight}
\newcommand{\xbox}[1]%
  {\savebox{\ximagebox}{#1}%
  \settoheight{\ximageheight}{\usebox{\ximagebox}}%
  \savebox{\xglyphbox}{\char32}%
  \settoheight{\xglyphheight}{\usebox{\xglyphbox}}%
  \raisebox{\ximageheight}[0pt][0pt]{\raisebox{-\xglyphheight}[0pt][0pt]{%
    \makebox[0pt][l]{\usebox{\xglyphbox}}}}%
    \usebox{\ximagebox}%
    \raisebox{0pt}[0pt][0pt]{\makebox[0pt][r]{\usebox{\xglyphbox}}}}

To be used as

\hyperlink{page.2}{\xbox{\includegraphics[height=14cm, width=14cm]{tiger}}}

Complete MWE follows:

\documentclass[landscape,a4paper,11pt]{article} 
\special{papersize=297mm,210mm}

\usepackage{graphicx}
%\usepackage[pdftex]{graphicx}

\usepackage{hyperref}

\usepackage[danish]{babel}

\DeclareGraphicsExtensions{.png,.pdf,.jpg,.mps}

\usepackage[top=2cm, bottom=2cm, left=3cm, right=3cm]{geometry}
\usepackage[absolute]{textpos}
\pagestyle{empty}

\setlength{\parindent}{0pt}

\usepackage{color}

\hypersetup{
    bookmarks=true,         % show bookmarks bar?
    unicode=false,          % non-Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,        % show Acrobat’s toolbar?
    pdfmenubar=true,        % show Acrobat’s menu?
    pdffitwindow=false,     % window fit to page when opened
    pdfstartview={FitH},    % fits the width of the page to the window
    pdftitle={My title},    % title
    pdfauthor={Author},     % author
    pdfsubject={Subject},   % subject of the document
    pdfcreator={Creator},   % creator of the document
    pdfproducer={Producer}, % producer of the document
    pdfkeywords={keyword1} {key2} {key3}, % list of keywords
    pdfnewwindow=true,      % links in new window
    colorlinks=false,       % false: boxed links; true: colored links
    linkcolor=black,          % color of internal links
    citecolor=green,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=cyan,           % color of external links
    pdfnonfullscreenpagemode=true,
    linktoc=none,
    pdfborder={ 0 0 0}
}


\newsavebox{\ximagebox}
\newlength{\ximageheight}
\newsavebox{\xglyphbox}
\newlength{\xglyphheight}
\newcommand{\xbox}[1]%
   {\savebox{\ximagebox}{#1}%
    \settoheight{\ximageheight}{\usebox{\ximagebox}}%
    \savebox{\xglyphbox}{\char32}%
    \settoheight{\xglyphheight}{\usebox{\xglyphbox}}%
    \raisebox{\ximageheight}[0pt][0pt]{\raisebox{-\xglyphheight}[0pt][0pt]{%
      \makebox[0pt][l]{\usebox{\xglyphbox}}}}%
    \usebox{\ximagebox}%
    \raisebox{0pt}[0pt][0pt]{\makebox[0pt][r]{\usebox{\xglyphbox}}}}

\begin{document}

\hyperlink{page.2}{\xbox{\includegraphics[height=14cm, width=14cm]{images/tiger}}}
\hyperlink{page.2}{\textblockcolour{white}{\fontsize{3mm}{5mm} \selectfont Dit hjem}}

\null\newpage
Some text

\end{document}
Related Question