Convert DOTX to MHTML using Python
DOTX to MHTML, HtmlFixed and HTML conversion in your Python Applications without installing Microsoft Word®.
Why to Convert DOTX to MHTML (Web Archive Format)
The DOTX file format is a Microsoft Word template file used to create documents. It is a compressed file format that stores text, images, and other media in a single file. MHTML (Web Archive Format) is a web page archive format used to store web pages in a single file. It is a combination of HTML and other resources such as images, audio, and video. Converting DOTX to MHTML (Web Archive Format) allows developers to save the document in the HTML format using absolutely positioned elements within the application.
How Aspose.Total Helps for DOTX to MHTML Conversion
Aspose.Total for Python via .NET is a full package of various APIs dealing different formats. We use Aspose.Words for Python via .NET API that is part of Aspose.Total for Python via .NET Package to add the DOTX to MHTML conversion feature. In case the DOTX file is simple then its just two lines of code. Load the DOTX 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.
How to Convert DOTX to MHTML in Python
- Load source DOTX 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 DOTX file is converted to MHTML at the specified path
Conversion Requirements
- For DOTX 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