How to add page break in HTML to PDF Conversion in WinForms?
The HTML-to-PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML files to PDF using C#. It is reliable and accurate. Using this library, you can add Page Break in HTML to PDF conversion using C#.
Steps to add Page Break in HTML to PDF conversion programmatically:
Note: When your HTML page uses these page breaks, then it can be reflected in the HTML to PDF conversion. Use the following HTML code example.
<html> <body> This is the text for page #1. <div style="page-break-before: always;"></div> Page #2... <div style="page-break-before: always;"></div> Page #3... </body> </html>
Create a new C# Windows Forms application project.
Include the following namespaces in the Form1.cs file.
using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO; using System;
- Create the button1_Click event and add the following code in button1_Click to add a page break in HTML to PDF conversion.
//Input the URL or file name. string url = Path.GetFullPath("Paginate.html"); //Initialize the HtmlConverter class. HtmlToPdfConverter html = new HtmlToPdfConverter(); BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); //Set the Blink viewport size. blinkConverterSettings.ViewPortSize = new Size(800, 0); //Set the BlinkConverterSettings property to the HtmlConverter. html.ConverterSettings = blinkConverterSettings; //Convert the URL to PDF. PdfDocument document = html.Convert(url); //Save the document. document.Save("Output.pdf"); //Close the document. document.Close(true);
A complete working sample can be downloaded from the HTML-to-PDF-page-break.zip.
By executing the program, you will get the PDF document as follows.
Take a moment to peruse the documentation where you can find other options like converting HTML to PDF, URL to PDF, HTML string to PDF, etc.
Refer here to explore the HTML to PDF features in Syncfusion Essential PDF.
An online sample link for converting HTML to PDF document.
Note: Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
I hope you enjoyed learning about how to add page break in HTML to PDF Conversion in WinForms.
You can refer to our
[https://www.syncfusion.com/document-processing/pdf-framework/net](WinForms PDF) page to know about its other groundbreaking feature representations and Documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-dayfree trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-trac, or feedback portal. We are always happy to assist you!