Articles in this section
Category / Section

How to Use print Media Type in HTML to WinForms PDF Conversion?

5 mins read

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

Using this library, you can set print media type while converting HTML to PDF document.

Steps to use print media type while converting HTML to PDF:

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

Create Windows Forms application in .NET PDF

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

NuGet package installation in .NET PDF

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

C#

using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using System.IO;
  1. Set the MediaType property available in the BlinkConverterSettings instance to set Print media type when HTML to PDF conversion. Please find the code snippet for the same from below.

C#

string url = Path.GetFullPath("../../Data/input.html");
 
//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
 
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
 
//Set MediaType property of BlinkConverterSettings
blinkConverterSettings.MediaType = MediaType.Print;
 
//Assign Blink settings to HTML converter
htmlConverter.ConverterSettings = blinkConverterSettings;
 
//Convert HTML to PDF
PdfDocument document = htmlConverter.Convert(url);
 
//Save and close the PDF document
document.Save("Sample.pdf");
document.Close(true);

A complete working sample can be downloaded from the HTMLtoPDF_Sample.zip.

Screenshot for print media type screenshot for print media type in .NET PDF

Screenshot for screen media type Screenshot for screen media type in .NET PDF

Take a moment to peruse the documentation for Converting HTML to PDF, where you will find converting HTML pages to PDF document along with the 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 on how to use print media type in HTML to WinForms PDF conversion.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example 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 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 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