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:
- 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.
- Invoke one of the Document.Save methods on the Document object and specify the desired output format.
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.
To convert a Microsoft Word document to HTML simply invoke the Document.Save method and specify a file name with the “.html” extension.
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.
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.
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.
The essential guide for designing a production-ready, developer-friendly RESTful API
Brian Neville-O'Neill -
Learning CMake 3: creating custom targets
Israel Blancas -
Fun with APIs: Building a Slack pinboard app!
How to fetch your public photos from Instagram without the API
Tero Auralinna -