Convert DOCM to MHTML using Python
DOCM to MHTML, HtmlFixed and HTML conversion in your Python Applications without installing Microsoft Word®.
Why to Convert DOCM to MHTML
The DOCM file format is a Microsoft Word document that is based on the Microsoft Office Open XML format. It is a combination of XML and binary files that are compressed into a single Zip archive. It is used to store documents with macros, which are pieces of code that automate tasks. The MHTML (Web archive format) is a web page archive format used to combine resources that are typically represented by external links (such as images, Flash animations, Java applets, and audio files) with HTML code into a single file. It is used to save web pages in a single file, and is supported by most web browsers. Converting a DOCM file to MHTML allows the document to be viewed in a web browser, and is also useful for archiving documents.
How Aspose.Total helps for DOCM to MHTML Conversion
Aspose.Total for Python via .NET is a full package of various APIs dealing different formats. It includes Aspose.Words for Python via .NET API that is used to add the DOCM to MHTML conversion feature. In case the DOCM file is simple then its just two lines of code. Load the DOCM file and call the save method with appropriate file path along with SaveFormat enumeration as MHTML or HTML_FIXED. But in case if there is need to restore the document model as close to original one then there is need to save some extra information within resultant document called round-trip information. This can be achieved by using Aspose.Words for Python via .NET API. It provides the capability to save the document in the HTML format using absolutely positioned elements. This helps to automate the conversion process and makes it easier for the Python developer to add the DOCM to MHTML conversion feature within the application.
How to Convert DOCM to MHTML in Python
- Load source DOCM 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 DOCM file is converted to MHTML at the specified path.
Conversion Requirements
- For DOCM 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