Articles in this section
Category / Section

Convert MHTML Files to PDF Documents Using ASP.NET Core

2 mins read

The Syncfusion® HTML-to-PDF converter is a PDF library for converting webpages, SVG, MHTML, and HTML files to PDF using C#. This guide covers the necessary steps, tools, and code examples to help you integrate MHTML to PDF conversion into your .NET Core applications.

Steps to convert MHTML to PDF programmatically

  1. Create a Console Application: Set up a new console application project.

    ConsoleApp.png

  2. Install Required Packages: Add the Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package from Nuget.org to your project.

    HTMLtoPDFWindows.png

  3. Set Up Your Environment: In the Program.cs file, include these namespaces.
    C#

using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
  1. Implement the Conversion Logic: Use the following code snippet in Program.cs to convert an MHTML file to a 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, the output PDF document will be generated as shown below:

Output.png

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!

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