Articles in this section
Category / Section

How to convert part of a webpage to WinForms PDF?

5 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 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 convert part of a webpage to PDF.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our  WinForms PDF documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms 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 WinForms PDF and otherWinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-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 (0)
Please  to leave a comment
Access denied
Access denied