I wish make a clickable text which redirects to an external pdf file. By using the hyperref package the link works only in the case the .tex file position is unchanged, so i would like to obtain the same effect permanently for any position.
Definitely i want to obtain the same effect of the hyperref package, but i would like this trick always works because i have to send this file to another person.
1 Answers
You cannot direct a link to an external file unless you can specify its location either remotely or locally. If you have no idea where it might be, you're toast. If you can count on the recipient putting the file in, say, the same directory as the current PDF, then you can specify a link. But if the recipient moves one of the files, the link will break.
What you can do is include another PDF in the main PDF, but without displaying the included PDF in the main one. That is, you can provide a link directed at the included file, such that, when clicked, the reader will be able to view that file.
The PDF specification supports two ways of doing this, both with LaTeX packages supporting them. First, you can embed the file. Then the reader will see a list of embedded files and will be able to view or save them, if desired. However, this list will not provide a clickable link on the page, even though there will be a clickable option presented to the reader. Rather, the PDF viewer will provide the link for the reader, when it detects that the PDF includes one or more embedded files.
Here's how a PDF with an embedded PDF presents the link in Okular:
The purple bar includes a blue link. If I click this link, Okular shows me a list of embedded files. Clicking on the embedded PDF, I can choose to save or view it. If I choose to view it, Okular opens it in a new tab (just to the right of this one in the shot above).
Second, you can attach the file. In this case, a link can be placed on a page of the main PDF. In this case, a link is created in the main PDF marked by an icon of some kind. This can either be left to the PDF viewer or determined by the PDF. However, using a custom icon comes with some caveats - see attachfile's manual for details.
Clicking on the icon offers me the option of saving the attached PDF to my disk. I don't have the option of viewing the PDF directly, without first saving it separately. I'm not sure whether this is due to my very limited experience with embedding and attaching files to PDF (I have about 20-30 minutes experience so far), a limitation of my PDF viewer or an inherent limitation of the mechanism supported by the PDF specification for attached, rather than embedded, files.
Code:
\pdfminorversion=7
\begin{filecontents}{\jobname-attach.tex}
\documentclass{article}
\begin{document}
\texttt{\jobname-attach.tex}
This is an attachment.
\end{document}
\end{filecontents}
\begin{filecontents}{\jobname-embed.tex}
\documentclass{article}
\begin{document}
\texttt{\jobname-embed.tex}
This is embedded.
\end{document}
\end{filecontents}
% note that the above must be compiled separately before compiling the completed document.
\documentclass{article}
\usepackage{embedfile,attachfile2,kantlipsum}
\begin{document}
% uncomment after first run and compilation of other files
%\embedfile{\jobname-embed.pdf}
\kant[1]
% uncomment after first run and compilation of other files, substituting the name of your main test file where indicated to give the name of the PDF to be attached
%\attachfile[icon=Paperclip, mimetype=pdf]{<substitute name of job here>-attach.pdf}
\end{document}
On the first run, this code will just typeset a paragraph of Kant and write two additional files to your working directory. Compile each of these files to PDF. Then uncomment the two lines indicated and substitute the name of your main test file in the indicated place for the \attachfile command. (\embedfile is happy to parse \jobname, whereas \attachfile is not.)
Then compile the example code again and you will find you have a main PDF with an embedded PDF, <name of job>-embed.pdf, and an attached PDF, <name of job>-attached.pdf.
In neither case does the link depend on knowing the location of a distinct PDF, but in neither case is the other PDF shown in the main file as it would be with, say, pdfpages.
- 198,882


\href{https://your.site/yourfile.pdf}{[title of yourfile]}– Toño Feb 06 '18 at 09:22pdfpages– Ignasi Feb 06 '18 at 09:44