Articles in this section
Category / Section

How to convert part of a webpage to WinForms PDF?

4 mins read

 The Syncfusion® HTML to PDF converter is a .NET PDF library for  converting webpages, SVG, MHTML, and HTML files to PDF using C#. The result preserves all graphics, images, texts, fonts, and the layout of the original HTML document or webpage.

Using this library, you can convert HTML string to PDF document using C#.

Steps to convert part of webpage to PDF programmatically:

  1. Create a new C# Windows Forms application project.

Creation of WF project

In project configuration window, name your project and click Create.

Project configuration window in WinForms PDF

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

Install NuGet package in WinForms PDF

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

C#

using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;

 

  1. Use the following code example to convert part of a webpage to PDF document in Form1.cs file.

C#

//Initialize the HTML to PDF converter.
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
 
//Convert Partial webpage to PDF.
PdfDocument document = htmlConverter.ConvertPartialHtml(htmlFilePath, "picture");
 
//Save and close the PDF document.
document.Save("Output.pdf");
document.Close(true);
 

 

A complete working sample can be downloaded from Convert_partial_webpage_to_PDF.zip.

By executing the program, you will get the PDF document as follows.

Input HTML file

Input HTML file

Output PDF document

Output PDF document

Take a moment to peruse the documentation, where you can find converting HTML pages to PDF document along with respective customization options and features.

Refer here to explore the rich set of Syncfusion Essential® PDF features.

An online sample link for Converting HTML to PDF.


Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion:

I hope you enjoyed learning about how to convert part of a webpage to WinForms PDF.

 

You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.

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 explore 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 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 (0)
Please  to leave a comment
Access denied
Access denied