rdvojmoc / DinkToPdf

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
MIT License
1.09k stars 417 forks source link

TOC (Table of Contents Support) #96

Open nichbeau opened 5 years ago

nichbeau commented 5 years ago

Just hoping anyone can help with using TOC (Table of Contents) in DinkToPDF. Currently there is no settings for it (like there is for Header and Footer etc). Any ideas of how to wrap it in so we can use the feature that is available would be great

garymcleanhall commented 4 years ago

In case anyone else ends up here needing a solution to this...

Subclass ObjectSettings and add a property to set the table of contents flag to true:

public class TableOfContentsSettings : ObjectSettings
{
    [WkHtml("isTableOfContent")]
    private bool IsTableOfContents
    {
        get => true;
    }
}

You can then add this object wherever you want the ToC to appear in the pdf. Something similar could probably be done with the Cover object type, but I've not got round to trying that (yet).

ghost commented 4 years ago

@garymcleanhall thanks, It worked but just the first time. I'm using .net core 2.2. After implemented, I call API to generate the PDF file. It works well for the first time and the next time, pdf file shows the blank page for TOC

PreshitDesai commented 1 year ago

It's working for me. Use the suggested class as the following.

var pdf = new HtmlToPdfDocument()
{
    GlobalSettings = globalSettings,
    Objects = { coverSettings, new TableOfContentsSettings(), objectSettings }
};
Recrox commented 9 months ago

Same here,

It works well for the first time and the next time, pdf file shows the blank page for TOC