Articles in this section
Category / Section

How to add page break in HTML to PDF Conversion in WinForms?

3 mins read

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


 
    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...


HTML screenshot.png

  1. Create a new C# Windows Forms application project. WF application creation.png

  2. Install the Syncfusion.HtmlToPdfConverter.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.

    NuGet package installation.png

  3. Include the following namespaces in the Form1.cs file.

C#

using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using System.IO;
using System;
  1. Create the button1_Click event and add the following code in button1_Click to add a page break in HTML to PDF conversion.

C#

//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.

Output PDF screenshot.png

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.

Conclusion

I hope you enjoyed learning about how to add page break in HTML to PDF Conversion in WinForms.

You can refer to our 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-day free 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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied