Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
Please add a minimal working example (MWE) that illustrates your problem. –  egreg Oct 17 '11 at 13:16
    
It would be a good idea to tell us what actually doesn't work. Also don't send code snippet. Always make a complete example, if I complete your code and use one of my graphics it works fine. –  Ulrike Fischer Oct 17 '11 at 13:20
    
In my code I have a menu with an image and a text. Both are inside \hyperlink so they link to another page in document, but only text works as a link. I cann`t click on image, cause somehow it doesnt work as link. <code> <br/> \hyperlink{page.3}{\includegraphics[height=14.869mm, width=14.869mm]{images/dig_og_din_naermeste}} <br/> \hyperlink{page.3}{\textblockcolour{white}{\fontsize{3mm}{5mm} \selectfont Dig og dine n\ae rmeste}} <code> –  joanna Oct 17 '11 at 13:40
1  
You should make a small complete example. That is one that starts with \documentclass and ends with \end{document}. Use either \usepackage[demo]{graphicx} or replace the image with one available for us too e.g. with "tiger". Add the example to your question, not as comment. Also put the log-file of the compilation somewhere on the net. –  Ulrike Fischer Oct 17 '11 at 13:53
    
I don't get any problem from your input file. –  egreg Oct 17 '11 at 14:16

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer
1  
XeTeX doesn't use xdv2pdf any more on Mac OS X. I couldn't replicate the problem. –  egreg Oct 17 '11 at 23:20
    
@egreg: I'm working on Linux, TeXlive 2011. I could replicate the problem- the above fixed it –  cmhughes Oct 17 '11 at 23:22
    
My experiment with a Linux box (Ubuntu Natty Narwhal, TeX Live 2011) shows that the original input shown by @joanna works as expected, turning the image into a link. –  egreg Oct 18 '11 at 8:15
1  
This \newsavebox works for me very well :) Thank you very much for help !!!! –  joanna Oct 18 '11 at 13:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.