[Tex/LaTex] Creating PDF with external link to open another PDF

hyperrefpdfpdftex

I am preparing a PDF file which will be put on the web. People will access it and should be able to open other pdf files from my PDF.

My commands works well for local pdf:

\href{run:./presentations/#1.pdf}

This is no brainer and it works.

However, when I publish my pdf file and have all the additional files in the presentations directory, this command does not work online.

If I use the absolute link as below

\href{http://127.0.0.1/presentations/#1.pdf}

it works. However, I need to be able to produce the pdf and then to store it onto a website with a relative link to the file. I am not able to "guess" the exact link that I will have to give.

I have tryed many usual short cuts:

\href{./presentations/#1.pdf}
\href{http://./presentations/#1.pdf}
\href{http:~/presentations/#1.pdf}

but none of them works.

Is there a way to have a relative link which will open?

Best Answer

AFAIK this is not possible. What you can do is to create a special \href Command and use a switch to switch from the online to the local version. The ifthen package would be a good starting point.

\documentclass[12pt,ngerman]{scrartcl}
\usepackage[]{ifthen}
\usepackage[]{hyperref}
\newboolean{online}
\setboolean{online}{true} 

\newcommand{\mylink}[1]{%
\ifthenelse{\boolean{online}}{%
\href{http://www.uweziegenhagen.de/materials/#1.pdf}{#1}%
}{%
\href{run:./presentations/#1.pdf}{#1}}}%

\begin{document}

\mylink{Uwe}

\end{document}
Related Question