Skip to content

Commit 248e6d2

Browse files
Merge pull request #1835 from syncfusion-content/994279-ug
994279-ug: Added TOC start page number by skipping the cover page
2 parents 690e4f3 + 756d475 commit 248e6d2

File tree

1 file changed

+90
-0
lines changed
  • Document-Processing/PDF/Conversions/HTML-To-PDF/NET

1 file changed

+90
-0
lines changed

Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,96 @@ padding-left: 5px;
807807

808808
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Create-custom-style-TOC-when-converting-HTML-to-PDF).
809809

810+
## Exclude cover page from TOC
811+
812+
This code snippet shows how to configure the Table of Contents (TOC) to skip the cover page by setting the starting page number. In this example, the cover page is a single page, so the TOC begins at page 1. For documents with multiple cover pages, adjust the starting page number as needed.
813+
814+
{% tabs %}
815+
816+
{% highlight c# tabtitle="C# [Cross-platform]" %}
817+
818+
using Syncfusion.Drawing;
819+
using Syncfusion.HtmlConverter;
820+
using Syncfusion.Pdf;
821+
822+
// Create an instance of HTML-to-PDF converter
823+
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
824+
// Configure Blink converter settings
825+
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings()
826+
{
827+
ViewPortSize = new Size(1280, 0), // Set viewport width for rendering
828+
EnableToc = true, // Enable Table of Contents (TOC)
829+
};
830+
// Set TOC starting page number to skip the cover page
831+
blinkConverterSettings.Toc.StartingPageNumber = 1;
832+
// Apply the settings to the converter
833+
htmlConverter.ConverterSettings = blinkConverterSettings;
834+
// Read the main HTML content and convert it to PDF
835+
string inputhtml = File.ReadAllText("input.html");
836+
PdfDocument document = htmlConverter.Convert(inputhtml, "");
837+
//Create cover page and insert to the 0th index.
838+
// Apply scaling settings for the cover page
839+
htmlConverter.ConverterSettings = new BlinkConverterSettings()
840+
{
841+
Scale = 1.5f
842+
};
843+
// Convert the cover page HTML to PDF
844+
string coverimage = File.ReadAllText("coverpage.html");
845+
PdfDocument coverPage = htmlConverter.Convert(coverimage, "");
846+
// Insert the cover page at the beginning of the main document
847+
document.Pages.Insert(0, coverPage.Pages[0]);
848+
// Save the PDF document
849+
document.Save("Output.pdf");
850+
//Dispose the document
851+
coverPage.Close(true);
852+
document.Close(true);
853+
htmlConverter.Close();
854+
855+
{% endhighlight %}
856+
857+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
858+
859+
Imports Syncfusion.Drawing
860+
Imports Syncfusion.HtmlConverter
861+
Imports Syncfusion.Pdf
862+
863+
' Create an instance of HTML-to-PDF converter
864+
Dim htmlConverter As New HtmlToPdfConverter()
865+
' Configure Blink converter settings
866+
Dim blinkConverterSettings As New BlinkConverterSettings() With {
867+
.ViewPortSize = New Size(1280, 0), ' Set viewport width for rendering
868+
.EnableToc = True ' Enable Table of Contents (TOC)
869+
}
870+
' Set TOC starting page number to skip the cover page
871+
blinkConverterSettings.Toc.StartingPageNumber = 1
872+
' Apply the settings to the converter
873+
htmlConverter.ConverterSettings = blinkConverterSettings
874+
' Read the main HTML content and convert it to PDF
875+
Dim inputhtml As String = File.ReadAllText("input.html")
876+
Dim document As PdfDocument = htmlConverter.Convert(inputhtml, "")
877+
' Create cover page and insert to the 0th index.
878+
' Apply scaling settings for the cover page
879+
htmlConverter.ConverterSettings = New BlinkConverterSettings() With {
880+
.Scale = 1.5F
881+
}
882+
' Convert the cover page HTML to PDF
883+
Dim coverimage As String = File.ReadAllText("coverpage.html")
884+
Dim coverPage As PdfDocument = htmlConverter.Convert(coverimage, "")
885+
' Insert the cover page at the beginning of the main document
886+
document.Pages.Insert(0, coverPage.Pages(0))
887+
' Save the PDF document
888+
document.Save("Output.pdf")
889+
' Dispose the documents
890+
coverPage.Close(True)
891+
document.Close(True)
892+
htmlConverter.Close()
893+
894+
{% endhighlight %}
895+
896+
{% endtabs %}
897+
898+
You can download a complete working sample from GitHub.
899+
810900
## Media Type
811901

812902
The Blink HTML Converter allows selection of media type while converting HTML to PDF. Blink rendering engine supports <b>Screen</b> and <b>Print</b> media types. Refer to the following code snippet to select Print [MediaType](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_MediaType).

0 commit comments

Comments
 (0)