I am exporting a very large document (1400+ pages) to ebook, and have already worked out the Table of Contents (ToC) as hyperlinks to all the chapters and sections, and the hyperlinks work fine after being exported to the target ebook format so that part is done.

Now I want to make all the link targets in the ToC into links themselves pointing back to the appropriate page of the ToC.

I do not wish to attempt this manually one by one, as there are hundreds of entries in the ToC, so I am looking for help to figure out how to take the link target information from the ToC, find said target in the text body, and then convert that target into a link pointing back to the correct ToC page automatically.

Thus my question is how to use a macro or Find/Replace to make ToC link targets into links themselves pointing back to the ToC in Libreoffice?

  • by ebook, do you mean epub or pdf? Also, is this ODT file a static doc or one you will be updating? Jul 19, 2022 at 20:43
  • I assume this ODT has lots of chapters -- in the epub output it will probably be separate HTML files so you are linking to separate HTML files and the anchors/ids. Therein lies the challenge. Jul 19, 2022 at 20:48
  • End product will be PDF
    – nijineko
    Jul 30, 2022 at 1:35
  • Maybe you're thinking about it wrong. You can simply delete the TOC and autogenerate it again. Autogenerating the TOC will check the headings and subheadings and put them into the TOC with everything linked properly. I don't think a programmatic or macro-based solution is necessary here. Jul 31, 2022 at 4:12
  • If you are using ODT styles correctly and applying headings and subheadings correctly to sections, autogenerating the TOC should be easy. Jul 31, 2022 at 4:14

1 Answer 1


I have never tried it before, but one option might be to convert it from ODT to epub using Calibre. It's a very user friendly tool, but also has lots of configurable options.

I don't see documentation for it, but I see a thread on mobileread (8 years old) where the lead developer (who made Calibre) comments that if the link is correctly made in ODT or .docx the links will be converted automatically in the epub output.

You should definitely try that. But first I would create a simple test document using three or four chapters (defined by the HEADING style) and then try the conversion and see what if anything needs to be tweaked.

Sometimes when I am doing a complicated conversation, it takes a few tries to work out (sometimes MS Word works better than LibreOffice for these advanced tasks, be forewarned).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.