0

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.

MWiesner
  • 225
FlyBob
  • 169
  • Try this command: \href{https://your.site/yourfile.pdf}{[title of yourfile]} – Toño Feb 06 '18 at 09:22
  • @Toño my .pdf is a local file, so i need to "incorporate" it in some manner – FlyBob Feb 06 '18 at 09:39
  • 1
    It is not clear to me what you really want to achieve. – AlexG Feb 06 '18 at 09:43
  • Do you want to "add" the pdf file to your final pdf file? Use pdfpages – Ignasi Feb 06 '18 at 09:44
  • See: https://tex.stackexchange.com/questions/46488/link-to-local-pdf-file?rq=1, https://tex.stackexchange.com/questions/41539/does-hyperref-work-between-two-files – Ignasi Feb 06 '18 at 09:46
  • @AlexG I would like to obtain a clickable text that open a local .pdf file. – FlyBob Feb 06 '18 at 10:11
  • @Ignasi Yes but i don't want to show it in the main file. I want to open it through a clickable text. Since i have to sent this file to another person, i can't use hyperref because, if i understood correctly, hyperef can open only local file. – FlyBob Feb 06 '18 at 10:34
  • Toño already showed you the command to open a file on a certain server. Did you try it? About your local file, will it be available to your colleague? If yes, use Toño's command. If not, will you send it to him? do you know its name and position as local file in you colleague's computer? If yes, use Toño's command, if not I don't know how to solve the problem. – Ignasi Feb 06 '18 at 10:49
  • @Ignasi Perhaps the OP wants to embed or attach one PDF in another? That's the closest I can think of. It isn't an external file, exactly, but its content is not displayed in the main PDF either. – cfr Feb 07 '18 at 04:01

1 Answers1

4

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:

Embedded file 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.

Attached file in Okular

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.

cfr
  • 198,882