Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Documents in HTML and MHTMLflow-layout formats are also very popular and can be used on any web platform. For that reason, converting documents to HTML and MHTML is an important feature of Aspose.Words.
EPUB (short for “Electronic Publication”) is an HTML-based format commonly used for electronic book distribution. This format is fully supported in Aspose.Words for exporting electronic books that are compatible with most reading devices.
For simple conversion to HTML, MHTML, or EPUB,one of theSavemethod overloads is used. You can save the document to a file or stream and explicitly set the output documentsave format or define it from the file name extension.
The following example shows how to convert DOCX to HTML with specifying a save format:
To convert a document to MHTML or EPUB, use SaveFormat::Mhtml or SaveFormat::Epub respectively.
The HTML format does not support many Microsoft Word features, and if we need to restore a document model as close to the original as possible, we need to save some extra information within the HTML file. Such information is also called “round-trip information”. For this purpose, Aspose.Wordsprovides an ability to export round-trip information when saving to HTML, MHTML, or EPUB using theExportRoundtripInformationproperty. Saving the round-trip information allows restoring document properties such as tabs, comments, headers, and footers during the loading documents of the listed formats back into aDocumentobject.
The default value istruefor HTML andfalsefor MHTML and EPUB:
The following code example shows how to export round‑trip information when converting a document from DOCX into HTML:
Aspose.Words allows converting a Word document to HTML using default or custom save options.Few examples of custom save options are described below.
Using Aspose.Words we can specify a physical folder where all resources, such as images, fonts, and external CSS, are saved when a document is converted to HTML. By default, this is an empty string.
Specifying theResourceFolderproperty is the simplest way to set the folder where all resources should be written. We can use individual properties, such asFontsFolderwhich saves fonts to the specified folder andImagesFolderwhich saves images to a specified folder.When a relative path is specified,FontsFolderandImagesFolderrefer to the folder where the code assembly is located,ResourceFolderandCssStyleSheetFileNamerefer to the output folder where the HTML document is located.
In this example,ResourceFolderspecifies the relative path. This path refers to the output folder where the HTML document is saved.The value of theResourceFolderAliasproperty is used to create URLs for all resources.
The following code example shows how to work with these properties:
Using theResourceFolderAliasproperty, we can also specify the name of the folder used to construct URIs of all resources written into an HTML document. This is the simplest way to specify how URIs should be generated for all resource files. The same information can be specified for images and fonts separately viaImagesFolderAliasandFontsFolderAliasproperties, respectively.
However, there is no individual property for CSS. The behavior of theFontsFolder,FontsFolderAlias,ImagesFolder,ImagesFolderAliasandCssStyleSheetFileNameproperties are not changed. Note that theCssStyleSheetFileNameproperty is used both for specifying folder name and file name.
Aspose.Words provides an ability tospecify whether font resources should be embedded into HTML in Base64 encodings. To perform this, use theExportFontsAsBase64property– this is an extension of theExportFontResourcesproperty. By default,its value isfalse,and fonts are written into separate files.But ifthis option is set totrue, fonts will be embedded into the document’s CSS in Base64 encoding. TheExportFontsAsBase64property only affects HTML format and does not affect EPUB and MHTML.
The following code example shows how to export Base64‑encoded fonts to HTML:
Aspose.Words allows converting a Word document into EPUB format using default or custom save options.You can specify a number of options by passing an instance ofHtmlSaveOptionsto the Save method.
The following code example shows how to converts a Word document to EPUB with specifying some custom save options:
Q: How do I convert a DOCX file to HTML using Aspose.Words for C++?
A: Load the document with Document doc("input.docx"); and call doc.Save("output.html", SaveFormat::Html);. This uses the default HtmlSaveOptions.
Q: How can I preserve Word‑specific features (round‑trip information) when saving to HTML?
A: Create an HtmlSaveOptions object, set options.set_ExportRoundtripInformation(true);, and pass it to Document::Save. This embeds additional CSS that allows the document to be re‑loaded with tabs, comments, headers, and footers restored.
Q: Where can I specify the folder for images, fonts, and other resources generated during HTML conversion?
A: Use HtmlSaveOptions options; then set options.set_ResourceFolder("Resources");, options.set_ImagesFolder("Resources/Images");, and options.set_FontsFolder("Resources/Fonts");. The folders are created automatically if they do not exist.
Q: How do I embed fonts directly into the HTML file as Base64 strings?
A: Set options.set_ExportFontsAsBase64(true); on an HtmlSaveOptions instance before saving. This causes font files to be encoded in Base64 and placed inside the generated CSS, eliminating external font files.
Q: What is the recommended way to convert a document to EPUB with custom options?
A: Although EPUB uses HtmlSaveOptions, you pass the same options to Document::Save with SaveFormat::Epub. For example:
HtmlSaveOptions options;
options.set_ExportFontResources(true);
options.set_ExportImagesAsBase64(true);
Document doc("input.docx");
doc.Save("output.epub", SaveFormat::Epub, &options);
This lets you control font embedding, image handling, and other EPUB‑specific settings.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.