Convert MHTML to DOCX in Python

MHTML to DOCX conversion is often required to take advantage of DOCX format for specific tasks. Aspose.HTML for Python via .NET provides a simple and efficient way to perform this conversion using convert_mhtml() methods of the Converter class.

In this article, you find information on how to convert MHTML to DOCX using Aspose.HTML Python library and how to apply DocSaveOptions.

To continue following this tutorial, install and configure Aspose.HTML for Python via .NET in your Python project.

Online MHTML Converter

You can convert MHTML to DOCX with Aspose.HTML for Python via .NET API in real time. Load an MHTML file from a local file system, select the output format and run the example. The conversion will be performed with default save options. You will immediately receive the conversion result as a separate file.

                
            

Convert MHTML to DOCX using DocSaveOptions

Using convert_mhtml() methods is the most common way to convert MHTML into various formats. With Aspose.HTML for Python via .NET, you can convert MHTML to DOCX format programmatically with full control over a wide range of conversion parameters.

To convert MHTML to DOCX with DocSaveOptions specifying, you should follow a few steps:

  1. Open an existing MHTML file. In the example, we use the open() method to open and read MHTML from a file system at the specified path.
  2. Create an instance of the DocSaveOptions class. The DocSaveOptions class provides numerous properties that give you full control over a wide range of parameters and improve the process of converting MHTML to DOCX format. In the example, we use the page_setup property that specifies the page size of the DOCX document, document_format, and css.media_type properties.
  3. Use one of the convert_mhtml() methods of the Converter class to save MHTML as a DOCX file. In the following example, the convert_mhtml() method takes the stream, options, output file path save_path and performs the conversion operation.

The following Python code example shows how to convert MHTML to DOCX using DocSaveOptions:

 1import os
 2from aspose.html import *
 3from aspose.html.converters import *
 4from aspose.html.saving import *
 5from aspose.html.drawing import *
 6
 7# Setup directories and define paths
 8output_dir = "output/"
 9input_dir = "data/"
10if not os.path.exists(output_dir):
11    os.makedirs(output_dir)
12document_path = os.path.join(input_dir, "document.mht")
13save_path = os.path.join(output_dir, "document.docx")
14
15# Open an existing MHTML file for reading
16with open(document_path, "rb") as stream:
17
18    # Create an instance of DocSaveOptions
19    options = DocSaveOptions()
20    options.page_setup.any_page = Page(Size(400, 400), Margin(10, 10, 10, 10))
21    options.document_format.DOCX
22    options.css.media_type.SCREEN
23
24    # Convert MHTML to DOCX
25    Converter.convert_mhtml(stream, options, save_path)

Save Options – DocSaveOptions Class

Aspose.HTML for Python via .NET allows converting MHTML to DOCX using default or custom save options. DocSaveOptions class is configured to save the document as DOCX and it includes the following properties:

Some properties of this class inherit properties of base classes, such as DocRenderingOptions or RenderingOptions.

Download the Aspose.HTML for Python via .NET library to successfully, quickly, and easily convert your HTML, MHTML, EPUB, SVG, and Markdown documents to the most popular formats.

Aspose.HTML offers a free online MHTML to DOCX Converter that converts MHTML to DOCX file with high quality, easy and fast. Just upload, convert your files and get results in a few seconds!

Text “MHTML to DOCX Converter”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.