Skip to content

Commit 9d0ee42

Browse files
committed
994279-ug: Added TOC start page number by skipping the cover page
1 parent eee63ac commit 9d0ee42

File tree

1 file changed

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

1 file changed

+95
-0
lines changed

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,101 @@ 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+
## Skip Cover Page in TOC Numbering
811+
812+
The following code snippet demonstrates how to set the starting page number for the Table of Contents (TOC) so that it skips the cover page. In this example, we have only one cover page, so the starting page number is set to 1. If your document includes multiple cover pages, you can adjust this value accordingly.
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 using Blink rendering engine
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 new settings for scaling the cover page
838+
BlinkConverterSettings settings = new BlinkConverterSettings();
839+
settings.Scale = 1.5f;
840+
// Apply scaling settings
841+
htmlConverter.ConverterSettings = settings;
842+
// Convert the cover page HTML to PDF
843+
string coverimage = File.ReadAllText("coverpage.html"));
844+
PdfDocument coverPage = htmlConverter.Convert(coverimage, "");
845+
// Insert the cover page at the beginning of the main document
846+
document.Pages.Insert(0, coverPage.Pages[0]);
847+
// Save the PDF document
848+
document.Save("Output.pdf"));
849+
// Close the PDF document
850+
document.Close(true);
851+
852+
{% endhighlight %}
853+
854+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
855+
856+
Imports Syncfusion.Drawing
857+
Imports Syncfusion.HtmlConverter
858+
Imports Syncfusion.Pdf
859+
860+
' Create an instance of HTML-to-PDF converter using Blink rendering engine
861+
Dim htmlConverter As New HtmlToPdfConverter()
862+
863+
' Configure Blink converter settings
864+
Dim blinkConverterSettings As New BlinkConverterSettings() With {
865+
.ViewPortSize = New Size(1280, 0), ' Set viewport width for rendering
866+
.EnableToc = True ' Enable Table of Contents (TOC)
867+
}
868+
869+
' Set TOC starting page number to skip the cover page
870+
blinkConverterSettings.Toc.StartingPageNumber = 1
871+
872+
' Apply the settings to the converter
873+
htmlConverter.ConverterSettings = blinkConverterSettings
874+
875+
' Read the main HTML content and convert it to PDF
876+
Dim inputhtml As String = File.ReadAllText("input.html")
877+
Dim document As PdfDocument = htmlConverter.Convert(inputhtml, "")
878+
879+
' Create new settings for scaling the cover page
880+
Dim settings As New BlinkConverterSettings()
881+
settings.Scale = 1.5F
882+
883+
' Apply scaling settings
884+
htmlConverter.ConverterSettings = settings
885+
886+
' Convert the cover page HTML to PDF
887+
Dim coverimage As String = File.ReadAllText("coverpage.html")
888+
Dim coverPage As PdfDocument = htmlConverter.Convert(coverimage, "")
889+
890+
' Insert the cover page at the beginning of the main document
891+
document.Pages.Insert(0, coverPage.Pages(0))
892+
893+
' Save the PDF document
894+
document.Save("Output.pdf")
895+
896+
' Close the PDF document
897+
document.Close(True)
898+
899+
{% endhighlight %}
900+
901+
{% endtabs %}
902+
903+
You can download a complete working sample from GitHub.
904+
810905
## Media Type
811906

812907
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)