Convert Word to HTML MHTML Programmatically using C++

HTML format is popular because it is supported on almost all computer environments. WORD to HTML or MHTML conversion is helpful in scenarios like when you need to display such a file in a web application using C++. Aspose.Words for C++ API is the best choice because of its features and efficiency. You can enrich your C++ applications with the ability to convert Microsoft Word files (DOC/DOCX) to HTML or MHTML format. Following is an outline of this article where we will be exploring Word conversion in detail:

C++ Microsoft Word Files Converter API – Installation

We need to install Aspose.Words for C++ API for converting Microsoft Word (DOCX/DOC) files. You can easily install the API from NuGet gallery or install it with the following command on the console.

Install-Package Aspose.Words.Cpp -Version 20.8.0

Convert Word (DOCX/DOC) to HTML using C++

Word to HTML conversion is helpful when you want to render contents in order to display that in a browser. Your C++ applications can quickly perform the conversion with the following steps:

  1. Load source word file
  2. Save the document in HTML format

The code below shows how to convert word to HTML using C++:

Convert Word to HTML with Embedded Fonts using C++

A word file (DOCX/DOC) may contain some custom font which might not be supported on some platforms. In such cases, the font may appear garbled in output results. However, Aspose.Words for C++ API lets you embed the font resources into HTML using Base64 encoding. You can set ExportFontsAsBase64 property which will embed fonts in the output HTML file. You need to follow the steps below to achieve these requirements:

  1. Load source DOCX file
  2. Set ExportFontsAsBase64 property
  3. Save the output HTML file

Following code snippet shows how to convert Word to HTML with Embedded fonts using C++:

Moreover, if you edit the HTML file with Notepad, or see the source code in a browser, then you can notice the Base64 fonts embedded into the file. Following screenshot shows an example from the output HTML file:

Convert Word to HTML

Convert Word to HTML with Round-Trip Information in C++

Microsoft Word documents can contain a lot of information and features which are otherwise not supported in HTML file format. Sometimes you need to convert Word to HTML and then back to Word format. To ensure maximum fidelity between these conversions, some information, known as “round trip information” can be saved additionally by Aspose.Words for C++ API. Let us follow the following steps to test such a conversion:

  1. Load source DOCX file
  2. Set ExportRoundtripInformation to true
  3. Save the output HTML file

The code snippet below shows how to convert Word to HTML with round-trip information using C++:

Convert Word to MHTML in C++

MHTML file format is popular as it contains all the contents within a single output file. You can convert Word file (DOCX/DOC) to MHTML format using C++ with following steps:

  1. Load source DOCX file
  2. Save output in MHTML format

The code snippet below shows how to convert Word to MHTML using C++:

Conclusion

We have learned how to convert Word (DOCX/DOC) to HTML or MHTML with different options. Several features like saving round trip information or embedding fonts as Base64 resources are also discussed in detail. However, in case of any questions, please feel free to contact us via Free Support Forum.

See Also

Make Fillable Form in Word using C#