loading...

Convert Microsoft Word Document to Other Formats in C++

sohailaspose profile image Sohail ・3 min read

Sometimes we need to programmatically convert Microsoft Word Document to PDF, HTML, EPUB or various other formats. But, most of the existing libraries require us to write a humungous amount of code. Moreover, complex documents are not converted correctly, either content is disturbed of the resulting document, fonts are missing, tables and lists are rendered incorrectly.

Fortunately, Aspose.Words for C++, a native class library, let us easily and reliably converts documents from one format to another. It just requires two lines of code:

  1. Load a document into a Document object using one of its constructors. By default, Aspose.Words will even auto-detect the file format for us.
  2. Invoke one of the Document.Save methods on the Document object and specify the desired output format.

Convert a Word Document to PDF

To convert a Microsoft Word document to PDF simply invoke the Document.Save method and specify a file name with the “.pdf” extension. The code sample below converts a whole document from DOC to PDF using default options.

Convert a Word Document to HTML

To convert a Microsoft Word document to HTML simply invoke the Document.Save method and specify a file name with the “.html” extension.

Export Fonts to HTML in Base64 Encoding

Using Aspose.Words, we can check whether font resources should be embedded to HTML in base 64 encodings. By default, the value is false and fonts are written to separate files. If this option is set to true, fonts will be embedded into the document's CSS in Base64 encoding. The property affects only HTML format and doesn't affect EPUB and MHTML. This is an extension to saveOptions->set_ExportFontResources option and ExportFontsAsBase64 will work only if this property set to true. Below example shows how to export fonts to HTML in Base64 encoding.

For more HtmlSaveOptions, please check the documentation and API Reference.

Convert a Document to EPUB

The electronic publication (an EPUB) document is an HTML-based format commonly used for electronic book distribution. This format is fully supported in Aspose.Words for exporting electronic books compatible with the majority of devices used for reading. This code sample shows how to convert simple MS Word document to EPUB with a few lines of code.

Installation

You may be wondering how to install Aspose.Words for C++ library. Please check this article, it provides step by step instructions to install the library.

Conversion is just one feature of Aspose.Words for C++, please check the Documentation to know about a number of other features.

If you need any assistance regarding Aspose.Words for C++, please visit Aspose.Forums. You can create a new topic over Aspose.Words for C++ forums and your post will be answered within a few hours.

Posted on by:

sohailaspose profile

Sohail

@sohailaspose

An experienced software architect and engineer with significant technical and project management experience.

Discussion

pic
Editor guide