How to convert part of a webpage to WinForms PDF?
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:
- Create a new C# Windows Forms application project.
In project configuration window, name your project and click Create.
Install the Syncfusion.HtmlToPdfConverter.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.
- Include the following namespaces in the Form1.cs file.
C#
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
- 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
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.
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!