Convert DOCX to MHTML using Python
DOCX to MHTML, HtmlFixed and HTML conversion in your Python Applications without installing Microsoft Word®.
As a Python developer, adding a DOCX to MHTML (Web archive format) conversion feature or HtmlFixed to save the document in the HTML format using absolutely positioned elements within an application can be a daunting task. Fortunately, Aspose.Total for Python via .NET API can help to automate the conversion process. It’s a full package of various APIs dealing different formats. In order to add the DOCX to MHTML conversion feature, we use Aspose.Words for Python via .NET API that is part of Aspose.Total for Python via .NET Package. If the DOCX file is simple, then it is just two lines of code. Load the DOCX file and call the save method with the appropriate file path along with SaveFormat enumeration as MHTML or HTML_FIXED. However, if there is a need to restore the document model as close to the original one, then there is a need to save some extra information within the resultant document called round-trip information. This can be done by using the Document.SaveOptions.SaveFormat property. The Aspose.Words for Python via .NET API also provides the ability to save the document in different formats such as PDF, XPS, HTML, and EPUB. It also supports the conversion of DOCX to MHTML and HTMLFixed formats. Furthermore, the API also provides the ability to convert the document to different image formats such as JPEG, PNG, and TIFF. Additionally, the API also provides the ability to convert the document to different text formats such as plain text, RTF, and XML. In conclusion, the Aspose.Total for Python via .NET API is an ideal solution for automating the DOCX to MHTML or HTMLFixed conversion process. It provides the ability to save the document in different formats, as well as the ability to save some extra information within the resultant document called round-trip information.
How to Convert DOCX to MHTML in Python
- Load source DOCX file using Document class
- Create the instance of HtmlSaveOptions
- Set the export_roundtrip_information as True
- Specify the SaveFormat as MHTML
- Call the
save
method while specifying output file path & SaveFormat as parameters. So your DOCX file is converted to MHTML at the specified path
Conversion Requirements
- For DOCX to MHTML or HtmlFixed format conversion, Python 3.5 or later is required
- Reference APIs within the project directly from PyPI ( Aspose.Words )
- Or use the following pip commands
pip install aspose.words
- Moreover, Microsoft Windows or Linux based OS (see more for Words ) and for Linux check additional requirements for gcc and libpython and follow step by step instructions INSTALL