Forum How do I...?

Internal links not working in PDF, prince-pdf-link-type CSS option not working

RichardForrester
I'm having a problem getting my cross-references in a table of contents section to work.

I think I've identified the problem as having something to do with the internal links. All of the internal links work correctly in HTML in the browser, but in the PDF the links reference a full url (http//localhost:8000/index#example-id). Clicking the links in the PDF causes the OS to try and access the page with the default web browser instead of traversing the PDF to the internal link.

Also, the "target-counter()" function fails and returns "0" for all links, making my table of contents broken.

I've tried to set the "prince-pdf-link-type: file" CSS property but it does not seem to work. Perhaps I am not putting it in the right place.

Any ideas?
mikeday
Does the URL in the links match the base URL of the document that you are providing to Prince? How exactly are you running Prince, with what input options?
RichardForrester
I'm running at http://localhost:8000/editor/display.

I cntr+s when I've got something to print out and save the entire page which comes with a folder. Then alt-tab to the terminal and run "prince filename.html"

The links in the PDF are actually the same as the links in the browser, e.g., "http://localhost:8000/editor/display#example-id"

So I if I knew what the links in the PDF where supposed to look like so they ran internally that might help be get an idea of where to go (maybe "~/tmp/filename.pdf#example-id" actually I'm sure that can't be right).

I've seen there are some options to remap the base URL like --baseurl=URL --remap=URL=DIR --fileroot=DIR, but I'm not sure which of those to use and how that should look because I'm not sure about the desired outcome.

I tried "prince filename.html --remap=http://localhost:8000/editor/display=~/tmp/" and I got an ignore message.
mikeday
This is a slightly tricky situation because the links are pointing to a HTTP URL but the document is now a local file, so there is no connection any more between the links and the document, and the links will remain pointing to the external URL.

You can specify the base URL of the document to be the original HTTP URL, eg. like this:

--baseurl=http://localhost:8000/editor/display

This should fix the links, but it will also make Prince load any relative URLs (eg. to images or style sheets) over HTTP, not from your local file copy.

The --remap option will not help in this situation as it only affects file loading, and links don't actually cause any files to be loaded so it will not apply.

Really the browser should have rewritten the internal links when it saved the file locally. If the links left out the document name and were just href="#example-id" then they would work no matter where the document was located.
RichardForrester
I can't believe it... Chrome fail.

I switched to Firefox to save the local copy and as you said, it rewrote the links to reference internally.

I didn't try the --baseurl option for the reasons you stated.

Thank you so much for the help, I was beginning to get a little too frustrated for my own good.

My faith in Google is shaken.
mikeday
In fairness sometimes you don't want the browser to rewrite links, if you want to check the exact source of the web page for some reason. But in this case I'm happy to blame Google. :D