athenapdf icon indicating copy to clipboard operation
athenapdf copied to clipboard

Table of Contents

Open douglasmiranda opened this issue 8 years ago • 7 comments

Would be awesome if we could generate a table of contents based on h1 - h6.

Ebooks. :D

(Currently I managed to achieve this only by compiling wkhtmltopdf or using the great, but EXPENSIVE PrinceXML)

douglasmiranda avatar Apr 14 '16 03:04 douglasmiranda

@douglasmiranda thanks for your request.

How is this currently done in wkhtmltopdf? Are you able to change the entire ToC template or are you only able to modify styles? What would you prefer?

MrSaints avatar Apr 14 '16 09:04 MrSaints

Actually I don't even remember, it generates some xml..

http://wkhtmltopdf.org/usage/wkhtmltopdf.txt http://www.princexml.com/doc/paged/

In both we can customize, but prince is better, we don't need xml file or stuff. We can, for example, just print every title linked to the respective title tags. And customize with some css.

<div id="toc">
  <h2>Table Of Contents</h2>
  <ul>
    <li><a href="#title-1">My First Chapter</a></li>
    <li><a href="#title-2">My Second Chapter</a></li>
  </ul>
</div>
<section>
  <h1 id="#title-1">Chapter One</h1>
</section>

I need to do some research on how they generate those outlines with the respective page numbers.

douglasmiranda avatar Apr 14 '16 17:04 douglasmiranda

@MrSaints how hard would it be to just inject some JavaScript to build the ToC in Electron?

dbuxton avatar Apr 14 '16 17:04 dbuxton

@douglasmiranda: Well, cross-referencing is supported in Athena (using page anchors). It's also pretty easy to create page breaks using the page-break-before CSS property (see https://gist.github.com/MrSaints/cc40127b54298910a6a8).

In theory, you can already create your own ToC, but if we want to create a built-in "plugin" it shouldn't be too hard (although, generating page numbers will probably be difficult @dbuxton). The question is how do we want to style / template it, because from my understanding, you can't alter the template in wkhtmltopdf.


Issues related to page numbering (from the looks of it wkhtmltopdf is affected by it too):

  • https://bugs.chromium.org/p/chromium/issues/detail?id=104154#c18
  • https://bugs.webkit.org/show_bug.cgi?id=85062
  • https://bugs.chromium.org/p/chromium/issues/detail?id=368053

MrSaints avatar Apr 14 '16 17:04 MrSaints

I see, the page numbering seems difficult. Yes, It seems I'm wrong about wkhtmltopdf. I probably should play more with Electron.

douglasmiranda avatar Apr 15 '16 02:04 douglasmiranda

I got a tad confused due to references to HTML/JS as I originally assumed this issue was about generating the TOC/navigation that appears within PDF viewers. Now, I believe this issue is actually about generating a TOC that is displayed within the document.

So, without meaning to hijack this issue, I just wanted to ask: is the generation of the TOC/navigation that is shown within PDF viewers already supported by AthenaPDF? I couldn't find anything in the code/docs.

JD-Robbs avatar Oct 03 '16 14:10 JD-Robbs

Auto-generated bookmarks from headings would be a great feature for athena. If it is a helpful reference, WeasyPrint currently supports this feature:

PDF bookmarks are also called outlines and are generally shown in a sidebar. Clicking on an entry scrolls the matching part of the document into view. By default all <h1> to <h6> titles generate bookmarks, but this can be controlled with CSS (see Bookmarks.)

dhimmel avatar Jun 24 '19 17:06 dhimmel