-
Notifications
You must be signed in to change notification settings - Fork 115
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
Table of Contents #282
Comments
Hey @map7 thanks for the suggestion. Although as far as I'm aware this is already supported (in a way) by Puppeteer/Chrome. See puppeteer/puppeteer#11779 Per the documentation it is still marked as experimental, but should just require passing through The feature does not add a static TOC with a summary of the headings etc in the way that you seem to be describing, but rather will add the TOC to the PDF so that suitable PDF readers will display it in the sidebar. To have something render an in-page TOC the problem is the data. It wouldn't be hard to use some script along with the See puppeteer/puppeteer#1778 (comment) and puppeteer/puppeteer#1778 (comment) for some examples of what others have done. HTH |
The project I was working on required a page with a TOC on the second page of the PDF document. I did managed to create a TOC but it's a work around and required pdf-reader, combine_pdf and prawn gems. After the pdf is created I read each page, look for headings and record the page and headings in a array of hashes. Then I used prawn to create the TOC, and then used combine_pdf to put the TOC on page two and create a new PDF. It actually works very well, it's just that I didn't want to bring all those GEMs in and create three files everytime I'm generating. I used Tempfile so there is no overlap. |
Sure, seems like a reasonable solution. So are you using prawn and grover? Or were you looking for an alternative that would negate the need for the combo? |
I'm currently using prawn and grover. It would be nice to have the functionality inbuilt into grover, rather than introducing more dependencies. Here is how I currently do it;
|
You could potentially create the TOC page by rendering your TOC to HTML then passing that into grover? It might be useful to create a "how to" document linked from the README that suggests how this problem can be solved. My concern with adding this as a built in feature is that it seems like it would require domain knowledge of the document being processed. eg your example code has this guard:
It could end up making things quite complicated if such cases needed to be handled within Grover. Also, if grover was to include such a feature I don't see that it would reduce the dependency count as it would likely want to use existing libraries (like PDF Reader and Combine PDF) for doing the "heavy lifting" anyway. Thank you for posting the detail on how you solved the problem 😄 |
If we lived in star trek times, I can foresee an API like this.
This would let us call arbitrary methods/view helpers at runtime on the controller that map to css classes like key/value pairs This something like this you could build arbitrary features like a TOC, or hiding page numbers on first/last pages, the sky is the limit. |
I'm struggling to see what you're getting at here? What is "controller" in this case? And what is "page"? Grover is simply rendering a URL or some HTML to a browser using Chrome. Where is it you are thinking the controller or page would be coming back through to "Ruby land" in this example? Your code suggest make It seem like you'd want it to somehow escape out of the Chrome render engine to do that! That might be possible.. but this is waaaay outside the scope of what Grover is for and can/will do. |
This is feature request. It would be nice if we could add a table of contents using grover with dynamic page numbers onto the second page (or nominated page). It's something which would have to be done after the PDF is created to get the page numbers or how the footer page numbers are dynamically calculated maybe the same code could be used.
Also if each item in the Table of Contents could be a link to the page that would be a great feature.
The text was updated successfully, but these errors were encountered: