Relative file links in pdf files

abcpdfhtml-to-pdfpdf

I'm creating a single pdf file that I'd like to link to other files in the same directory as the pdf.

ie.

MyFolder
        |
        |-main.pdf
        |-myotherpdf.pdf
        |-myotherotherpdf.pdf

I'd like the main.pdf to have links that would cause the default program on the pdf to open the other pdfs.

As I am generating these file on a server and then providing them in a download to the client I cannot use absolute links as these would not exist on the client pc.

So firstly do pdf files actually support relative file links like this, I haven't found much that says they do either way.

Additionally to generate my pdf I'm using abcpdf and providing it html to convert to pdf.

To try and generate the correct out the correct urls in html I have tried the following

<a href='test.pdf'>test pdf link to local file</a>
<a href='#test.pdf'>test pdf link to local file</a>
<a href='/test.pdf'>test pdf link to local file</a>
<a href='file:///test.pdf'>test pdf link to local file</a>
<a href='file://test.pdf'>test pdf link to local file</a>

Most of them either direct to me a point where the pdf document was generated from (temporary file path) or they link hovering shows "file:///test.pdf" in acrobat but clicking it causes a warning dialog to popup asking to allow/deny, upon clicking allow it opens up in firefox with the url "file:///test.pdf" which wouldn't resolve to anything.

Any ideas on how to get this working or if this kind of linking is even possible in pdfs?

Best Answer

I can only answer your question: does PDF files actually support relative file links like this?

Yes, it does. I created a little test with a main.pdf that has two links to two other PDF documents in the same folder. I created the links manually with Acrobat and associated a launch action with the link annotation. See the internal structure here:

enter image description here

Here is the zip with the main plus two secondary PDFs. Note that you can copy them anywhere and the relative links remain valid. https://www.dropbox.com/s/021tvynkuvr63lv/main.zip

I am not sure how you would accomplish this with abcpdf, especially since you are converting from HTML which probably limits the PDF features available.

Related Topic