arachnys / athenapdf

Drop-in replacement for wkhtmltopdf built on Go, Electron and Docker
MIT License
2.26k stars 186 forks source link

Table of Contents #16

Open douglasmiranda opened 8 years ago

douglasmiranda commented 8 years ago

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)

MrSaints commented 8 years ago

@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?

douglasmiranda commented 8 years ago

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.

dbuxton commented 8 years ago

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

MrSaints commented 8 years ago

@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):

douglasmiranda commented 8 years ago

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

JD-Robbs commented 8 years ago

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.

dhimmel commented 5 years ago

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.)