QuestPDF / QuestPDF

QuestPDF is a modern open-source .NET library for PDF document generation. Offering comprehensive layout engine powered by concise and discoverable C# Fluent API. Easily generate PDF reports, invoices, exports, etc.
https://www.questpdf.com
Other
11.64k stars 604 forks source link

Add Support for Table of Contents #13

Closed MarkoH17 closed 3 years ago

MarkoH17 commented 3 years ago

Is your feature request related to a problem? Please describe. Many real world reports contain a Table of Contents to support easy navigation between sections. For QuestPDF to be useful in generating these documents, there needs to be an easy way to generate a Table of Contents table.

Describe the solution you'd like It would be ideal to add a new component for TableOfContents. Components to be shown in the Table of Contents could have a boolean property such as "VisibleInTableOfContents" set to "True".

Describe alternatives you've considered I've reviewed the sample TableOfContentsTemplate.cs and though this provides navigation in the document, the page numbers in the output PDF document are incorrect. I have been unable to find a way to reference the page number that a specific component is located on.

MarcinZiabek commented 3 years ago

@MarkoH17 Thank you for your suggestion. Indeed, it is a missing feature that many may find really important. I am aware that the QuestPDF library lacks the ability to create tables of contents and show the total number of pages on each page. I am struggling with how to exactly implement such features. In most common implementations, it is common that you need to perform the layouting algorithm twice which may significantly reduce the performance. Once - to get information about page number where the given element has appeared, and then second - to draw the content with proper information. To some extent, with specifically crafted layouts, you may need an infinite number of passes.

I will try to fit this feature in one of the future updates. So far, I am planning to improve text rendering capabilities, debugging experience and redesign documentation.

Do you have any suggestions how the API may look like for such mentioned table of contents feature? I see it may be a special component/element or some kind of text tags that will be replaced with values during report rendering.

MarcinZiabek commented 3 years ago

The suggested feature is analyzed and planned to be implemented in one of the nearest updates. W know which changes are required to make it work. I am not able to provide any exact time roadmap though.

In case of any suggestions or requirements, let's continue the discussion here.

MarcinZiabek commented 3 years ago

Update: good news! I am working on this change right now. Please expect this feature to be available in the next release 2021.08. Any updates regarding API design and breaking changes I will post here.

MarcinZiabek commented 3 years ago

@MarkoH17 This functionality is available within the QuestPDF 2021.08 release.

Please refer to the documentation about placeholders in the PageNumber element: https://www.questpdf.com/documentation/api-reference.html#page-number

As well as to the internal example with a table of content: https://github.com/QuestPDF/library/blob/main/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs

MarkoH17 commented 3 years ago

@MarcinZiabek This is great! I will test this out on a few projects I have going. Closing this issue, as support for page numbers was added in the 2021.08 release.