MHTML Converter in Java

Aspose.HTML for Java converts MHTML or MHT archives to PDF, XPS, DOCX, JPG, PNG, BMP, GIF, and TIFF. Open the source as a file, stream, or URL, create the save options for the required output, and call Converter.convertMHTML().

MHTML, also known as MIME HTML, is a MIME-based web archive format described in RFC 2557 and commonly stored with the .mht or .mhtml extension. It packages HTML markup and handled resources, such as stylesheets and images, into one archive. Converting MHTML is useful when an archived web page must be distributed, printed, edited, or represented as a static image.

How MHTML Conversion Works

  1. Prepare the MHTML source as a local file, supported stream, or URL.
  2. Create the save options for the required output, such as PdfSaveOptions, XpsSaveOptions, DocSaveOptions, or ImageSaveOptions.
  3. Call a Converter.convertMHTML() overload with the source, save options, and output path.

The following example opens sample.mht as a FileInputStream, uses the default PdfSaveOptions, and converts the archive to convert-by-two-lines.pdf.

1// Convert MHTML to PDF using Java
2
3// Open an existing MHTML file for reading
4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht");
5
6// Invoke the convertMHTML() method to convert MHTML to PDF
7Converter.convertMHTML(fileInputStream, new PdfSaveOptions(), "convert-by-two-lines.pdf");

Download complete Java examples and data files from GitHub.

MHTML Conversion Guides

Related MHTML Workflows

Other Platforms

Try Online MHTML Conversion

Use the free online MHTML Converter for quick manual conversion to PDF, XPS, DOCX, or image formats without writing Java code. Use Aspose.HTML for Java when MHTML conversion must run programmatically.