preview – Keep copy/paste and TOC in PDF converted from ebook?

For research, I often convert non-DRM ebooks to PDF using Calibre. The resulting PDF has a TOC with working links. However, it is not searchable in Preview, and copy/paste results in blank white space, even when pasting into TextEdit or nValt.

(Adobe Acrobat can search, copy/paste the PDF and the TOC works, but I use many tools that use Apple’s PDF frameworks, so I’d like to solve this.)

To make it searchable and copyable, I run the PDF through Ghostscript using these commands:

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=”output” “input”

This renders a new PDF that is searchable, and copy/pastes properly. However, it strips the links from the TOC.

Is there a way to convert the PDF so that it will retain its TOC links and also be searchable and have copy/paste work?

Catalina – Pages – ToC insert on page

I am preparing a diary for my club with Pages 10.0 on macOS 10.15.3 (previously I used other tools).
This is almost complete, but I'm having trouble inserting a table of contents.

I have a ToC that I can display in the sidebar but want to insert into my document.
This is a word processing document, and the first page contains text in multiple text boxes.

I was hoping to insert a ToC in a text box to the right of the boiler plate, but this doesn't seem to be supported.
I managed to insert a ToC, but it is on a separate page.
I could select this and copy it into the text box, but it lost the links to the table of contents

I used columns for other tools, but this doesn't seem to be possible.

There will only be fewer than 20 entries in the ToC, but I'm even struggling to keep it on the first page.
Can anyone suggest a solution?