Is your feature request related to a problem? Please describe.
I have a large set of data that will generate a pdf so I am looking for a way to generate TOC automatically.
There was similar kind of functionality in pdfmake that uses pdfkit as well. I was looking for similar kind of thing with react-pdf.
Hi,
What did you mean by "generate TOC automatically"?
Assuming that you are asking by some kind of component that automatic generate a page with the ToC,
I think the react-pdf is a low level lib to create pdf in a declarativel way and this kind of component can be create using the build blocks already provided. As a prove of concept see the project attached (read App.js and toc,js)
Would be wonderful if the community developed something like twitter bootstrap for this library, with commonly used components. But unfortunately I do not have time to start a project like these :(
This approach does not handle the page numbers in the ToC. You'd still need a third pass to get those as the page numbers cannot be detected before the second finishes, unless you want to have the ToC at the end of the produced PDF.
Latex is doing three renderings to get numbering correctly.
Thanks for that info @vstirbu !
Could you refer me to where I can see in more detail how latex does this?
I totally forgot about the page numbering :disappointed:
I was thinking about it and came with the ideia of a "document event" that is emitted after layout but before the painting, and allow to any listener of this event call setState reacting to layout variables (like the page number and the bounding rect).
this can depreciate the dynamic render (aka render prop) and allow much more complex features. But I don't think this is a easy thing to implement, because it will envolve:
There is some performance implication too, but I think is impossible to beat the numbering problem and others (e.g. ensure chapter start on even pages) without a performance penalty. And this strategy will move the performance considerations to the user (e.g. avoiding change things that cause re-layout) when they consider this a problem.
Yes, there would definitely be a performance penalty for this case but not all pdf documents have this kind of formatting/style requirements.
If the step is opt in, the users would be aware of what it implies performance wise and can make an informed decision. I would assume that documents containing ToCs are generated in a batch fashion so the doc does not have to be available immediately.
If it makes things better, the last re-rendering applies only to Table of Contents/Images/Tables/etc. components, while the rest remain unchanged and might even have the layout cached...
@diegomura The latex tooling hides quite well the document generation process these days but the problem of getting correctly the cross references still exists. There is a brief explanation in the thread
@diegomura Has there been any updates on this? Is it not possible right now to produce the page numbers in a TOC?
Most helpful comment
This approach does not handle the page numbers in the ToC. You'd still need a third pass to get those as the page numbers cannot be detected before the second finishes, unless you want to have the ToC at the end of the produced PDF.
Latex is doing three renderings to get numbering correctly.