Forum How do I...?

Calibre plugin to convert epub hyperlinks to footnotes

TonyDawson
I am using the Prince PDF plugin for Calibre (latest versions). I have azw3 & epub files with endnotes that are formatted as hyperlinks rather than true endnotes.

I need to convert these hyperlinks to real footnotes at the bottom of each page.

Can you confirm if this is possible with Prince PDF please?

If so, what do I type in the Custom Styles window?

Thanks

Tony







TonyDawson
To clarify, the input is azw3 or epub with hyperlinks to notes at the end of each book.

The desired output is a pdf with footnotes at the bottom of each page.
mikeday
If the endnotes are currently hyperlinks to content later in the document this will require using JavaScript to collect that content and insert it inline where the footnote should go and apply the appropriate CSS styling.
cony
Hello there,

Sorry for the bump but since this is 100% my issue, I thought it would be best not to create a new topic.

I just came across Prince today and I'm very much in the same boat as the thread creator: Using the Prince PDF plugin in Calibre, trying to convert an epub file with hyperlinks instead of true endnotes to a PDF that has them as footnotes on the same page.

Prince seems to be the only solution I found that has the capability to handle this properly. A workaround by means of converting epub -> docx -> pdf is unsuitable because there are apparently too many hyperlinks in the file for Word to handle (it goes unresponsive for 45min+ when I try to replace all hyperlinks with footnotes using VBA).

Could you please elaborate on your previous post and provide a sample script, Mike? The solution seems sound but I'm not sure how to realize it.

To clarify, the hyperlinks have the format of /path/to.html#ftn.footnoteid

Thank you so much!
mikeday
It is actually possible to do a simple version of this purely in CSS using the target-content() function, see the attached example below. This will not capture markup present in the footnote elements however.

I was going to create a JavaScript example to do something similar but along the way I hit an unexpected issue with the DOM API so I might investigate that further before proceeding. :D
  1. footnotes1.html0.6 kB
mikeday
Actually it wasn't too bad, the JavaScript version is attached.
  1. footnotes2.html0.9 kB
cony
Thank you very much for your reply! I will try to get it to work based on either of your solutions :)

Edited by cony

mikeday
One minor issue: the footnotes2.html example refers to "a.hash", however on closer inspection Prince is currently returning the .hash value without a leading "#" character, which is incorrect. We will fix this in a future release of Prince, after which it will be necessary to use a.hash.substring(1) to access the ID.
rpd123
Cony, I’m in the same boat and am trying to go via Word first - would you be willing to share the code you used in VBA? I’m not particularly au fait with the software, and know it didn’t work for you, but would like to give it a go!
fbrzvnrnd
Hi, I get an

prince: /Users/fabriziovenerandi/Documents/footnotes2.html:8: error: TypeError: null value is not an object


trying to compile the footnotes2.html example with Prince 10. I'm missing something?

Thank you

Fabrizio
mikeday
Minor bug sorry, it needs to strip the leading # from the link hash property, see below.
  1. footnotes2.html1.0 kB
fbrzvnrnd
Thank you, I'll found the hint last night in your previous comment :D One last question: is there a way to use the column-count in footer? If I use the column-count in @footer nothing happens, if I use it in ftn-copy class, every single note create a separate column reflow.
fbrzvnrnd
A very last question: is it correct the script is not working if the notes and the text body are in two separate files?