Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOC with page numbers #21

Open
kohheepeace opened this issue Jun 4, 2021 · 2 comments
Open

TOC with page numbers #21

kohheepeace opened this issue Jun 4, 2021 · 2 comments
Labels
difficult help wanted Extra attention is needed

Comments

@kohheepeace
Copy link
Owner

I have no clean idea.

ref: https://medium.com/@pofider/generate-pdf-with-toc-using-chrome-c3b44f924ff9

@kohheepeace kohheepeace added help wanted Extra attention is needed difficult labels Jun 4, 2021
@pkowaluk
Copy link

pkowaluk commented Jul 14, 2022

Hey, @kohheepeace , do you mind if I pick this one up? We would like to use Mr. PDF in our project and a TOC with page numbers would be great.

Do you have any contributing guidelines in mind, or can I just fork and propose a PR?

@josefloidolt
Copy link

I don't have the prettiest solution, but it worked for me.
I added the TOC with page numbers like this:

  1. You have to generate the pdf with the TOC (without page numbers)
  2. You read out the metadata of the pdf
  3. Now you can filter out the headings by the font size and you also get the page number (where the heading is placed)
  4. You store each (heading/page number) pair in a Map
  5. Now you have to generate the pdf once again in order to add the page numbers to the table of contents
  6. You have your finished pdf

Note: if your pdf contains a long heading you have to take that into account when adding the page numbers to the TOC. You may have to merge the map entries so that the headings match.

I hope this solution was helpful. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficult help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants