Convert WORD to MHTML using Python
WORD to MHTML, HtmlFixed and HTML conversion in your Python Applications without installing Microsoft Word®.
As a Python developer, adding a WORD to MHTML (Web archive format) conversion feature or HtmlFixed mean saving the document in the HTML format using absolutely positioned elements within application. To automate the process, Aspose.Total for Python via .NET API can be used. It is a full package of various APIs dealing with different formats.
Aspose.Words for Python via .NET API, which is part of Aspose.Total for Python via .NET Package, can be used to add the WORD to MHTML conversion feature. If the WORD file is simple, then it is just two lines of code. The first line is to load the WORD file and the second line is to 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, which is called round-trip information.
The API provides a wide range of features such as document conversion, document manipulation, document comparison, document signing, and many more. It also supports various file formats such as DOC, DOCX, ODT, RTF, HTML, PDF, XPS, EPUB, and many more. Furthermore, it also provides the ability to convert documents to different formats such as HTML, MHTML, XPS, PDF, and many more.
How to Convert WORD to MHTML in Python
- Load source WORD 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 WORD file is converted to MHTML at the specified path
Conversion Requirements
- For WORD 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