Table of Contents

Class HtmlToPdfToc

Namespace
Syncfusion.Pdf.HtmlToPdf
Assembly
Syncfusion.Pdf.Portable.dll

Class which provides method and properties to apply styles in automatic creation of a table of contents items for the H1 to H6 HTML elements

public class HtmlToPdfToc
Inheritance
HtmlToPdfToc
Inherited Members

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

Remarks

To know more about HTML to PDF TOC refer this link.

Constructors

HtmlToPdfToc()

Initializes a new instance of the HtmlToPdfToc class.

public HtmlToPdfToc()

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set the maximum header level.
toc.MaximumHeaderLevel = 5;
//Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash;
//Set table leader character.
toc.TabLeaderChar = 'c';                
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set the maximum header level.
toc.MaximumHeaderLevel = 5
'Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash
'Set table leader character.
toc.TabLeaderChar = "c"
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

Properties

MaximumHeaderLevel

Gets or sets the maximum header level (H1 to H6) :By default 6

public int MaximumHeaderLevel { get; set; }

Property Value

int

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set the maximum header level.
toc.MaximumHeaderLevel = 5;
//Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash;
//Set table leader character.
toc.TabLeaderChar = 'c';                
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set the maximum header level.
toc.MaximumHeaderLevel = 5
'Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash
'Set table leader character.
toc.TabLeaderChar = "c"
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

StartingPageNumber

Gets or sets the starting page number for table of contents in HTML to PDF conversion.

public int StartingPageNumber { get; set; }

Property Value

int

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Going to insert two pages before TOC, so added the offset value as 2 
settings.Toc.StartingPageNumber = 2;    
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
//Going to insert two pages before TOC, so added the offset value as 2 
settings.Toc.StartingPageNumber = 2;   
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

TabLeader

Gets or sets the tab leader:By default Dot

public HtmlToPdfToc.TabLeaderStyle TabLeader { get; set; }

Property Value

HtmlToPdfToc.TabLeaderStyle

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set the maximum header level.
toc.MaximumHeaderLevel = 5;
//Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash;
//Set table leader character.
toc.TabLeaderChar = 'c';                
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set the maximum header level.
toc.MaximumHeaderLevel = 5
'Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash
'Set table leader character.
toc.TabLeaderChar = "c"
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

TabLeaderChar

Gets or sets the tab leader character to connect the chapter titles and section headings to their corresponding page numbers

public char TabLeaderChar { get; set; }

Property Value

char

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set the maximum header level.
toc.MaximumHeaderLevel = 5;
//Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash;
//Set table leader character.
toc.TabLeaderChar = 'c';                
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set the maximum header level.
toc.MaximumHeaderLevel = 5
'Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash
'Set table leader character.
toc.TabLeaderChar = "c"
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

Title

Gets or sets the TOC title

public string Title { get; set; }

Property Value

string

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

TitleAlignment

Gets or sets the horizontal title text alignment:By default left

public PdfTextAlignment TitleAlignment { get; set; }

Property Value

PdfTextAlignment

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

TitleStyle

Gets or sets the TOC style of the table of contents title. When this property is set with a value, the default style of the title is replaced with the style given by this property.

public HtmlToPdfTocStyle TitleStyle { get; set; }

Property Value

HtmlToPdfTocStyle

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)

Methods

SetItemStyle(int, HtmlToPdfTocStyle)

Sets the style of a table of contents item on a given level. The item level is a number from 1 to 6

public void SetItemStyle(int headingStyle, HtmlToPdfTocStyle tocStyle)

Parameters

headingStyle int
tocStyle HtmlToPdfTocStyle

Examples

//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
//Create a new instance for webkit converter settings.
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
//Enable toc.
settings.EnableToc = true;
//Create a new instance for HTML to PDF toc.
HtmlToPdfToc toc = new HtmlToPdfToc();
//Set title.
toc.Title = "HTML to PDF";
//Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center;
//Create new HTML to PDF Toc Style.
HtmlToPdfTocStyle style = new HtmlToPdfTocStyle();
//Set background color.
style.BackgroundColor = new PdfSolidBrush(Color.LightCyan);
//Set font.
style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Set fore color.
style.ForeColor = new PdfSolidBrush(Color.Red);
//Set paddings.
style.Padding = new PdfPaddings(5, 5, 5, 5);
//Set toc style.
toc.TitleStyle = style;
//Set the maximum header level.
toc.MaximumHeaderLevel = 5;
//Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash;
//Set header1 style.
toc.SetItemStyle(1, style);
//Set header2 style.
toc.SetItemStyle(2, style);      
//Set toc to webkit settings.
settings.Toc = toc;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework");
//Save and close the PDF document 
document.Save("Output.pdf");
document.Close(true);
'Initialize HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
'Create a new instance for webkit converter settings.
Dim settings As New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "/QtBinaries/"
'Enable toc.
settings.EnableToc = True
'Create a new instance for HTML to PDF toc.
Dim toc As New HtmlToPdfToc()
'Set title.
toc.Title = "HTML to PDF"
'Set title alignment.
toc.TitleAlignment = PdfTextAlignment.Center
'Create new HTML to PDF Toc Style.
Dim style As New HtmlToPdfTocStyle()
'Set background color.
style.BackgroundColor = New PdfSolidBrush(Color.LightCyan)
'Set font.
style.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Set fore color.
style.ForeColor = New PdfSolidBrush(Color.Red)
'Set paddings.
style.Padding = New PdfPaddings(5, 5, 5, 5)
'Set toc style.
toc.TitleStyle = style
'Set the maximum header level.
toc.MaximumHeaderLevel = 5
'Set tab leader style.
toc.TabLeader = HtmlToPdfToc.TabLeaderStyle.Dash
'Set header1 style.
toc.SetItemStyle(1, style)
'Set header2 style.
toc.SetItemStyle(2, style)
'Set toc to webkit settings.
settings.Toc = toc
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://en.wikipedia.org/wiki/.NET_Framework")
'Save and close the PDF document 
document.Save("Output.pdf")
document.Close(True)