gitbook icon indicating copy to clipboard operation
gitbook copied to clipboard

Conversion to PDF with calibre should show table of content with page numbers

Open sudheesh001 opened this issue 10 years ago • 18 comments

The table of contents end up showing the section numbers to the right instead of the page numbers. Having it display the page numbers is generally what's expected.

I am not sure if this is the right place to post about this, but it'd be nice if there's a method in the book.json which would allow the book to be rendered with page numbers in the Table of Contents than the section numbers.

This is how the rendered book using gitbook pdf looks as of now.

screen shot 2016-04-12 at 10 40 56 am

The book lies at : https://github.com/GameAutomators/eBook-Source

Thank you so much for this amazing tool.

sudheesh001 avatar Apr 12 '16 05:04 sudheesh001

+1 would be great :)

bronestly avatar Apr 14 '16 22:04 bronestly

Is there any possibility to hide the TOC in PDFs, until this bug is fixed?

Tiliavir avatar Apr 21 '16 17:04 Tiliavir

can be "fixed" using:

Hide Chapter Numbers

.section.toc .page {
    display: none;
}

Hide TOC

.section.toc {
    display: none;
}

Tiliavir avatar Apr 22 '16 14:04 Tiliavir

@Tiliavir Great ! That hides the table of contents, it'd be best to have gitbook render the page numbers instead too 😄

sudheesh001 avatar Apr 22 '16 14:04 sudheesh001

I've found the problem is not on gitbook itself, but on the default template. As you can see, the structure is title-level. This makes me think I'm not sure if it would be easy (or possible) to get the chapters page numbers because probably this is managed by calibre itself and/or the PDF reader since there are only links and the content can flow (think about long summaries that could extend to several pages...), but doing it in two loops (one to place the pages in position using placeholders for the page numbers, and another one to update the PDF to set the final values) would do the trick...

piranna avatar Apr 24 '16 11:04 piranna

@piranna I think it's okay for most users to have the render to pdf take some time as long as it contains page numbers in the PDF. It's something most textbooks have and making gitbook have that would be just plain awesome.

sudheesh001 avatar Apr 24 '16 16:04 sudheesh001

I totally agree, GitBook books MUST have page numbers on the index at least in ready-to-print PDFs, and in fact is one of the requeriments of my thesis tutor. My complaints where about complexity to do it, since probably we would need to modify the generated PDF, or generate it twice. Other option would be to generate and replace twice only the summary... Is there any method to get the chapter pages from the generated PDF file? El 24/4/2016 6:23 PM, "Sudheesh Singanamalla" [email protected] escribió:

@piranna https://github.com/piranna I think it's okay for most users to have the render to pdf take some time as long as it contains page numbers in the PDF. It's something most textbooks have and making gitbook have that would be just plain awesome.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/GitbookIO/gitbook/issues/1223#issuecomment-213996576

piranna avatar Apr 24 '16 16:04 piranna

There is an option in calibre, that writes a toc at the end of the book ... I've tested it with gitbook, but a TOC at the end was not an option for us, however, this thing has page numbers ...

--pdf-add-toc Add a Table of Contents at the end of the PDF that lists page numbers. Useful if you want to print out the PDF. If this PDF is intended for electronic use, use the PDF Outline instead.

from: https://manual.calibre-ebook.com/generated/en/ebook-convert.html#pdf-output-options

Maybe it is possible to get the required information from here and than to update the TOC at the beginning?

Tiliavir avatar Apr 26 '16 15:04 Tiliavir

Are you suggesting it's a problem of Calibre? El 26/4/2016 5:40 PM, "Markus Lindenmann" [email protected] escribió:

there is an option in calibre, that writes a toc at the end of the book ... I've tested it with gitbook, but a TOC at the end was not an option for us, however, this thing has page numbers ...

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/GitbookIO/gitbook/issues/1223#issuecomment-214787101

piranna avatar Apr 26 '16 15:04 piranna

Other option would be, generate the book with this index and later extract it and put at begining... El 26/4/2016 5:47 PM, [email protected] escribió:

Are you suggesting it's a problem of Calibre? El 26/4/2016 5:40 PM, "Markus Lindenmann" [email protected] escribió:

there is an option in calibre, that writes a toc at the end of the book ... I've tested it with gitbook, but a TOC at the end was not an option for us, however, this thing has page numbers ...

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/GitbookIO/gitbook/issues/1223#issuecomment-214787101

piranna avatar Apr 26 '16 15:04 piranna

Well I fear calibre has kind of the same problem. I think the reason of putting the TOC at the end is just a hack since they know all the page numbers there / at the end of creating the whole document (and my interpretation: they are too lazy or it is too complicated to update / insert a TOC at the beginning).

What I tried to say: maybe it is possible to take the information from the Calibre generated TOC and use it in the own TOC ... This requires two runs and seems very hacky, but since perfomance is not a problem ... and at least it could kind of work ...

Tiliavir avatar Apr 26 '16 16:04 Tiliavir

Yeah, but besides the proof of concept, I think we should ask Calibre devs about fixing this. El 26/4/2016 6:02 PM, "Markus Lindenmann" [email protected] escribió:

Well I fear calibre has kind of the same problem. I think the reason of putting the TOC at the end is just a hack since they know all the page numbers there (and my interpretation: they are too lazy or it is too complicated to update / insert a TOC at the beginning).

What I tried to say: maybe it is possible to take the information from the Calibre generated TOC and use it in the own TOC ... This requires two runs and seems very hacky, but since perfomance is not a problem ... and at least it could kind of work ...

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/GitbookIO/gitbook/issues/1223#issuecomment-214794423

piranna avatar Apr 26 '16 16:04 piranna

The best solution will be that Calibre supports CSS printing standard such as counter, footnotes, etc More info.

We could solve the page numbers in the TOC using:

ul.toc a::after {
  content: leader('.') target-counter(attr(href), page);
}

But Calibre doesn't support leader and target-counter

SamyPesse avatar May 10 '16 12:05 SamyPesse

The best solution will be that Calibre supports CSS printing standard such as counter, footnotes, etc More info.

Just that page gave me the inspiration to write my thesis using HTML before I knew about GitBook :-P

piranna avatar May 10 '16 21:05 piranna

For those who need to add page numbers right now, I've made a GitBook PDF generator with wkhtmltopdf. See #1470 for a sample.

(I didn't publish an npm yet, so you need to use the code in the sample directly. Remember to do npm install before running the generator. For discussions, go to #1470.)

@SamyPesse : I'm continuing to push a departure from Calibre for PDF generation. Sorry for the push. The requirements for PDF for printing is very different from ebooks, so one product does not fit all.

lwchkg avatar Aug 10 '16 15:08 lwchkg

Any updates on this?

trufae avatar Aug 21 '18 22:08 trufae

Has anyone found a workaround for that yet?

reflectively avatar Oct 17 '18 12:10 reflectively

Not me.. but i’m very interested on having this too. Last time i end up doing it by hand with a pdf editor :(

On 17 Oct 2018, at 14:27, reflectively [email protected] wrote:

Has anyone found a workaround for that yet?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

trufae avatar Oct 17 '18 18:10 trufae