Convert HTML to MHTML – Aspose.HTML Cloud SDK

Converting between formats is required for various reasons: to work in a familiar, convenient format or to take advantage of different formats for specific tasks. Aspose.HTML Cloud provides the simplest way to convert HTML documents to MHTML format with high quality, easy and fast.

MHTML combines HTML and its associated resources (images, stylesheets, and scripts) into a single file. HTML to MHTML conversion makes it easier to archive and share web content by combining all related resources into one self-contained file. Moreover, HTML to MHTML conversion offers benefits such as offline browsing, saving web content, email attachments, regulatory compliance, etc.

This article contains code examples explaining how to convert HTML to MHTML using available SDKs. We will consider various HTML to MHTML conversion scenarios: from storage to storage, a local file to a local file system, and from the Web to the local file system.

Examples of HTML to MHTML Conversion

Aspose.HTML Cloud allows you to fetch an HTML document from a storage location by its name, from a URL or a local file on your drive, convert it to the specified format and save it to the storage or the local drive. The following code examples demonstrate how to convert HTML to MHTML programmatically for different cases.

Example 1. Convert HTML to MHTML with default save options

Consider an example of converting a local HTML file to MHTML and saving the result to a local path.

Example 2. Convert a Web page to MHTML

Converting to MHTML helps maintain the integrity and structure of web pages, ensuring that all elements are preserved for future use or redistribution. Aspose.HTML Cloud allows you to get a web page by its URL, convert it to another format and save into a local file system. The example below demonstrates how to convert a web page to MHTML with the default conversion parameters.

HTML to MHTML conversion occurs with the default conversion options: the resulting MHTML document’s width and height correspond to A4, and all margins have zero value.

Example 3. Convert HTML to MHTML inside cloud storage

Aspose.HTML Cloud allows you to get an HTML file from your cloud storage and save conversion result back to cloud storage.

See Also