How to Convert MHTML files to PDF documents in ASP.NET Core PDF?
The Syncfusion; HTML-to-PDF converter is a PDF library for converting webpages, SVG, MHTML, and HTML files to PDF using C#. It uses the popular rendering engine Blink (Google Chrome). It is reliable and accurate. The conversion process preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage. Using this ASP.NET Core PDF library, you can easily convert MHTML files to documents.
Steps to convert MHTML to PDF programmatically
- Create a new console application project.
- Install the Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package as a reference in your console application from Nuget.org.
- Include the following namespaces in the Program.cs file.
C#
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
- Use the following code sample in Program.cs to convert MHTML files into PDF document.
C#
// Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
// Convert the MHTML content to PDF
PdfDocument document = htmlConverter.Convert("Data/Input.mhtml");
// Save the PDF document to a file
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
document.Save(outputFileStream);
}
// Close the PDF document
document.Close(true);
A complete working sample is available for download from GitHub.
By executing the program, you will generate the following PDF document.
Take a moment to peruse the documentation, where you will find features for converting HTML pages into PDF documents.
Conclusion
I hope you enjoyed learning about how to convert MHTML files to PDF documents in ASP.NET Core PDF.
You can refer to our ASP.NET Core 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 ASP.NET Core 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!