Document ClassesHyperref links to all other files except pdfs

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
alackofcolor
Posts: 6
Joined: Wed Jan 09, 2008 1:38 am

Hyperref links to all other files except pdfs

Post by alackofcolor »

I'm trying to insert a link that when clicked will open another pdf file. I'm using the MacTex 2007 installation and TexShop that outputs a pdf file when typeset. I included the \usepackage{hyperref} command in the beginning of the document and the following type of command to reference the file

\href{file:///pathtofilefolder/file.pdf}{Caption}

The problem is, when clicking the link in the outputted pdf file, nothing happens. There is a box around the link to indicate it's there, but it never opens when the link is to a pdf document. I've linked to other document types, .psd, .eps, .png, etc and when the link is clicked, the documents open up fine. Any ideas?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Re: Hyperref links to all other files except pdfs

Post by Juanjo »

Do you append "//" right after "file:" ? I think this may cause the problem. I have tried something like
\href{file:/Users/myname/Desktop/myfile.pdf}{text} and it works fine. You can also try to write "run" instead of "file".
alackofcolor
Posts: 6
Joined: Wed Jan 09, 2008 1:38 am

Re: Hyperref links to all other files except pdfs

Post by alackofcolor »

I removed the two extra "//" and got the same results as before, it won't open a pdf file, but it opened a png, and I presume that it would open all of the others I tried before. I tried "run:" instead of "file:" and nothing opened.

I checked my log file and I am using version 6.75r of hyperref. Was yours a newer version? Also, the color of the link around the link when trying to link to a pdf is a darker blue than when linking to other file types, does that indicate anything?
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Hyperref links to all other files except pdfs

Post by Juanjo »

We are using the same version of hyperref. Please, provide a minimal working example and attach a small pdf, so I can try it myself. It would be also useful the log file. Without seeing some code and checking the pdf file, I cannot figure out where the problem is.
alackofcolor
Posts: 6
Joined: Wed Jan 09, 2008 1:38 am

Re: Hyperref links to all other files except pdfs

Post by alackofcolor »

My input can be simplified to the following point to illustrate that it doesn't work for pdfs but does for other formats:

\documentclass[12pt]{report}
\usepackage{hyperref}
\begin{document}

\href{file:/Users/Jeremy/Documents/University%20of%20Cincinnati/Electrodynamics/Notes/Supplements/Solid%20Angle.pdf}{Testing}

\end{document}

Obviously the file path is unique to my computer, but substitution of your own would check the correctness of the input. I should probably stress that replacing the pdf at the end of the file name with a png links fine to a png file with the same name in the same folder. I will attach an example pdf and a log file. Are you using the 2007 MacTeX-2007 package? Because I tried this same type of thing today on a school computer with the same MacTeX-2007 install and got the same results as at home and I was wondering if it is a problem with the package.
Attachments
Solid Angle.pdf
(84.49 KiB) Downloaded 370 times
Untitled-2.log
(5.39 KiB) Downloaded 360 times
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Hyperref links to all other files except pdfs

Post by Juanjo »

After some tests I am convinced that the problem comes from the path and from the file name . They contain blank spaces which are represented by %20. Replace them by \ (backslash and space). So, instead of a path like

/Users/my%20name/my%20folder/Solid%20Angle.pdf,

write

/Users/my\ name/my\ folder/Solid\ Angle.pdf

This works on my Mac. It should also work in yours, since we are using the same TeX distribution.

Good luck
alackofcolor
Posts: 6
Joined: Wed Jan 09, 2008 1:38 am

Re: Hyperref links to all other files except pdfs

Post by alackofcolor »

Thanks for all of the help, but unfortunately replacing the spaces did not work. I even tried linking to a pdf file with no spaces in the name of the file or the path to the file and it didn't work, but it did for other file types. I find it odd that it works for you but it doesn't on my computer or on my school computer which has the same TeX distribution. When you try it, do you have anything in the preamble that I don't have? Any packages loaded that I may need? Or did you just try what I posted? And are you opening the pdfs in Acrobat, Preview, or just in the TeXShop preview?
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Hyperref links to all other files except pdfs

Post by Juanjo »

I have tried exactly the code you posted, changing only the path to one in my computer having some blank spaces. Perhaps it is an issue concerning either the operating system (mine is 10.3.9, by now, although this will change in a very near future with a new Intel Mac :) ) or the version of Adobe Reader (7.0.9).

Let's do a final test. Write a tex file with the following code:

Code: Select all

\documentclass[12pt]{report}
\usepackage{hyperref}
\begin{document}
\href{file:./LaTeX\ Community/Solid\ Angle.pdf}{File keyword}

\href{run:./LaTeX\ Community/Solid\ Angle.pdf}{Run keyword}
\end{document} 
Put it, say, in the Desktop folder and create there a sub-folder called LaTeX Community. Put there Solid Angle.pdf. Compile the tex file. I attach the pdf I obtain. Check both pdf files with Adobe and other pdf viewers. Does any of the pdf work?
Attachments
LinkTest.pdf
(6.66 KiB) Downloaded 436 times
alackofcolor
Posts: 6
Joined: Wed Jan 09, 2008 1:38 am

Re: Hyperref links to all other files except pdfs

Post by alackofcolor »

Success, I finally got it to work, using the run command you suggested, but a few things still strike me as odd.

1. The file: command does not work for pdfs, but does for other all other file types I tried using an absolute file address, not one relative to the document. So something like file:/Users/Jeremy/Documents/University%20of%20Cincinnati/Solid%20Angle.pdf

2. The run: command does not work with absolute addresses like the one given above, just addresses relative to where the document is saved and links do not work in TeXShop pdf viewer, I had to use Preview for working links, which is fine.

3. The run: command did not work for a png. file with the same name as the pdf and which was in the same folder as the pdf file, which is fine because I can open png files using the file: command with an absolute address.

4. The run: command did not work for relative address with spaces, meaning all folder and file names relative to the document must contain no spaces, which is fine because all it meant was I had to change Solid Angle.pdf to Solid-Angle.pdf. Using the file: command I could have spaces by putting a %20, or a \%20 in. A \ with a space after it never worked for any of them.

In the end I find this all very confusing as to why some things work but others don't. I did get what I wanted to work with your help, so thanks a lot for putting time into getting this sorted out.
Post Reply