Bad Dub
Bad Dub

Reputation: 1593

Change ToC Font-Family and Size Using NReco HTML-to-PDF C#

I'm using NReco to convert HTML views to PDF files in a C# project. Everything works perfectly but I'm struggling to set the Font-Family and Font-Size properties of the generated ToC as it doesnt match the rest of the document.

This is my code currently:

var pdfConverter = new HtmlToPdfConverter
{
    Orientation = PageOrientation.Landscape,
    PageFooterHtml = "<div style=\"font-family: Arial;\">Page: <span class=\"page\"></span> of <span class=\"topage\"></span></div>",      
    GenerateToc = true
};

There is a property available called CustomWkHtmlTocArgs that I know I should be using to solve this but I don't know what to assign to this variable.

I think I need to create a XSLTstyle sheet or something?

Upvotes: 0

Views: 2134

Answers (1)

Vitaliy Fedorchenko
Vitaliy Fedorchenko

Reputation: 9245

Your suggestion is correct, NReco.PdfGenerator internally uses wkhtmltopdf and if you want to change default TOC layout and/or styles you need to specify custom XSL for TOC:

pdfConverter.CustomWkHtmlTocArgs = " --xsl-style-sheet full_path_to_your_toc.xsl ";

To get sample (default) XSL file run:

> wkhtmltopdf.exe --dump-default-toc-xsl > toc.xsl

You can get more details about wkhtmltopdf options here: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

Upvotes: 1

Related Questions