com.aspose.words

Class HtmlSaveOptions

  • java.lang.Object
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class HtmlSaveOptions 
    extends SaveOptions

Can be used to specify additional options when saving a document into the SaveFormat.HTML, SaveFormat.MHTML or SaveFormat.EPUB format.

Example:

Shows how to set save options before saving a document to HTML.
Document doc = new Document(getMyDir() + "Rendering.doc");

// This is the directory we want the exported images to be saved to.
File imagesDir = new File(getMyDir(), "SaveHtmlWithOptions");

// The folder specified needs to exist and should be empty.
if (imagesDir.exists()) {
    imagesDir.delete();
}

imagesDir.mkdir();

// Set an option to export form fields as plain text, not as HTML input elements.
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setExportTextInputFormFieldAsText(true);
options.setImagesFolder(imagesDir.getPath());

doc.save(getArtifactsDir() + "Document.SaveWithOptions.html", options);

Example:

Shows how to define custom logic for controlling how images are saved when exporting to HTML based formats.
public void saveHtmlExportImages() throws Exception {
    Document doc = new Document(getMyDir() + "Document.doc");

    // Create and pass the object which implements the handler methods.
    HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
    options.setImageSavingCallback(new HandleImageSaving());

    doc.save(getArtifactsDir() + "Document.SaveWithCustomImagesExport.html", options);
}

public class HandleImageSaving implements IImageSavingCallback {
    public void imageSaving(final ImageSavingArgs args) throws Exception {
        // Change any images in the document being exported with the extension of "jpeg" to "jpg".
        if (args.getImageFileName().endsWith(".jpeg"))
            args.setImageFileName(args.getImageFileName().replace(".jpeg", ".jpg"));
    }
}

Example:

Converts a document to EPUB with save options specified.
// Open an existing document from disk.
Document doc = new Document(getMyDir() + "Document.EpubConversion.doc");

// Create a new instance of HtmlSaveOptions. This object allows us to set options that control
// how the output document is saved.
HtmlSaveOptions saveOptions = new HtmlSaveOptions();

// Specify the desired encoding.
saveOptions.setEncoding(Charset.forName("UTF-8"));

// Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
// which allows you to limit the size of each HTML part. This is useful for readers which cannot read
// HTML files greater than a certain size e.g 300kb.
saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);

// Specify that we want to export document properties.
saveOptions.setExportDocumentProperties(true);

// Specify that we want to save in EPUB format.
saveOptions.setSaveFormat(SaveFormat.EPUB);

// Export the document as an EPUB file.
doc.save(getArtifactsDir() + "Document.EpubConversion.epub", saveOptions);

Example:

Shows how split a document into parts and save them.
public void documentParts() throws Exception {
    // Open a document to be converted to html
    Document doc = new Document(getMyDir() + "Rendering.doc");
    String outFileName = "SavingCallback.DocumentParts.Rendering.html";

    // We can use an appropriate SaveOptions subclass to customize the conversion process
    HtmlSaveOptions options = new HtmlSaveOptions();

    // We can use it to split a document into smaller parts, in this instance split by section breaks
    // Each part will be saved into a separate file, creating many files during the conversion process instead of just one
    options.setDocumentSplitCriteria(DocumentSplitCriteria.SECTION_BREAK);

    // We can set a callback to name each document part file ourselves
    options.setDocumentPartSavingCallback(new SavedDocumentPartRename(outFileName, options.getDocumentSplitCriteria()));

    // If we convert a document that contains images into html, we will end up with one html file which links to several images
    // Each image will be in the form of a file in the local file system
    // There is also a callback that can customize the name and file system location of each image
    options.setImageSavingCallback(new SavedImageRename(outFileName));

    // The DocumentPartSaving() and ImageSaving() methods of our callbacks will be run at this time
    doc.save(getArtifactsDir() + outFileName, options);
}

/// <summary>
/// Renames saved document parts that are produced when an HTML document is saved while being split according to a criteria
/// </summary>
private static class SavedDocumentPartRename implements IDocumentPartSavingCallback {
    public SavedDocumentPartRename(String outFileName, int documentSplitCriteria) {
        mOutFileName = outFileName;
        mDocumentSplitCriteria = documentSplitCriteria;
    }

    public void documentPartSaving(DocumentPartSavingArgs args) throws Exception {
        Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));

        String partType = "";

        switch (mDocumentSplitCriteria) {
            case DocumentSplitCriteria.PAGE_BREAK:
                partType = "Page";
                break;
            case DocumentSplitCriteria.COLUMN_BREAK:
                partType = "Column";
                break;
            case DocumentSplitCriteria.SECTION_BREAK:
                partType = "Section";
                break;
            case DocumentSplitCriteria.HEADING_PARAGRAPH:
                partType = "Paragraph from heading";
                break;
        }

        String partFileName = MessageFormat.format("{0} part {1}, of type {2}.{3}", mOutFileName, ++mCount, partType, FilenameUtils.getExtension(args.getDocumentPartFileName()));

        // We can designate the filename and location of each output file either by filename
        args.setDocumentPartFileName(partFileName);

        // Or we can make a new stream and choose the location of the file at construction
        try {
            FileOutputStream outputStream = new FileOutputStream(getArtifactsDir() + partFileName);
            args.setDocumentPartStream(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }

        Assert.assertNotNull(args.getDocumentPartStream());
        Assert.assertFalse(args.getKeepDocumentPartStreamOpen());
    }

    private int mCount;
    private String mOutFileName;
    private int mDocumentSplitCriteria;
}

/// <summary>
/// Renames saved images that are produced when an HTML document is saved
/// </summary>
public static class SavedImageRename implements IImageSavingCallback {
    public SavedImageRename(String outFileName) {
        mOutFileName = outFileName;
    }

    public void imageSaving(ImageSavingArgs args) throws Exception {
        // Same filename and stream functions as above in IDocumentPartSavingCallback apply here
        String imageFileName = MessageFormat.format("{0} shape {1}, of type {2}.{3}", mOutFileName, ++mCount, args.getCurrentShape().getShapeType(), FilenameUtils.getExtension(args.getImageFileName()));

        args.setImageFileName(imageFileName);

        try {
            FileOutputStream outputStream = new FileOutputStream(getArtifactsDir() + imageFileName);
            args.setImageStream(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }

        Assert.assertNotNull(args.getImageStream());
        Assert.assertTrue(args.isImageAvailable());
        Assert.assertFalse(args.getKeepImageStreamOpen());
    }

    private int mCount;
    private String mOutFileName;
}

Constructor Summary
HtmlSaveOptions()
Initializes a new instance of this class that can be used to save a document in the SaveFormat.HTML format.
HtmlSaveOptions(intsaveFormat)
Initializes a new instance of this class that can be used to save a document in the SaveFormat.HTML, SaveFormat.MHTML or SaveFormat.EPUB format.
 
Property Getters/Setters Summary
booleangetAllowNegativeIndent()
void
           Specifies whether negative left and right indents of paragraphs are normalized when saving to HTML, MHTML or EPUB. Default value is false.
intgetColorMode()
void
setColorMode(intvalue)
           Gets or sets a value determining how colors are rendered. The value of the property is ColorMode integer constant.
java.lang.StringgetCssClassNamePrefix()
void
setCssClassNamePrefix(java.lang.Stringvalue)
           Specifies a prefix which is added to all CSS class names. Default value is an empty string and generated CSS class names have no common prefix.
ICssSavingCallbackgetCssSavingCallback()
void
           Allows to control how CSS styles are saved when a document is saved to HTML, MHTML or EPUB.
java.lang.StringgetCssStyleSheetFileName()
void
setCssStyleSheetFileName(java.lang.Stringvalue)
           Specifies the path and the name of the Cascading Style Sheet (CSS) file written when a document is exported to HTML. Default is an empty string.
intgetCssStyleSheetType()
void
           Specifies how CSS (Cascading Style Sheet) styles are exported to HTML, MHTML or EPUB. Default value is CssStyleSheetType.INLINE for HTML/MHTML and CssStyleSheetType.EXTERNAL for EPUB. The value of the property is CssStyleSheetType integer constant.
java.lang.StringgetDefaultTemplate()
void
setDefaultTemplate(java.lang.Stringvalue)
           Gets or sets path to default template (including filename). Default value for this property is empty string.
intgetDmlEffectsRenderingMode()
void
           Gets or sets a value determining how DrawingML effects are rendered. The value of the property is DmlEffectsRenderingMode integer constant.
intgetDmlRenderingMode()
void
           Gets or sets a value determining how DrawingML shapes are rendered. The value of the property is DmlRenderingMode integer constant.
IDocumentPartSavingCallbackgetDocumentPartSavingCallback()
void
           Allows to control how document parts are saved when a document is saved to HTML or EPUB.
intgetDocumentSplitCriteria()
void
           Specifies how the document should be split when saving to SaveFormat.HTML or SaveFormat.EPUB format. Default is DocumentSplitCriteria.NONE for HTML and DocumentSplitCriteria.HEADING_PARAGRAPH for EPUB. The value of the property is DocumentSplitCriteria integer constant.
intgetDocumentSplitHeadingLevel()
void
           Specifies the maximum level of headings at which to split the document. Default value is 2.
java.nio.charset.CharsetgetEncoding()
void
setEncoding(java.nio.charset.Charsetvalue)
           Specifies the encoding to use when exporting to HTML, MHTML or EPUB. Default value is 'UTF-8' Charset.
intgetEpubNavigationMapLevel()
void
           Specifies the maximum level of headings populated to the navigation map when exporting to IDPF EPUB format. Default value is 3.
booleangetExportCidUrlsForMhtmlResources()
void
           Specifies whether to use CID (Content-ID) URLs to reference resources (images, fonts, CSS) included in MHTML documents. Default value is false.
booleangetExportDocumentProperties()
void
           Specifies whether to export built-in and custom document properties to HTML, MHTML or EPUB. Default value is false.
booleangetExportDropDownFormFieldAsText()
void
           Controls how drop-down form fields are saved to HTML or MHTML. Default value is false.
booleangetExportFontResources()
void
           Specifies whether font resources should be exported to HTML, MHTML or EPUB. Default is false.
booleangetExportFontsAsBase64()
void
           Specifies whether fonts resources should be embedded to HTML in Base64 encoding. Default is false.
intgetExportHeadersFootersMode()
void
           Specifies how headers and footers are output to HTML, MHTML or EPUB. Default value is ExportHeadersFootersMode.PER_SECTION for HTML/MHTML and ExportHeadersFootersMode.NONE for EPUB. The value of the property is ExportHeadersFootersMode integer constant.
booleangetExportImagesAsBase64()
void
           Specifies whether images are saved in Base64 format to HTML, MHTML or EPUB. Default is false.
booleangetExportLanguageInformation()
void
           Specifies whether language information is exported to HTML, MHTML or EPUB. Default is false.
intgetExportListLabels()
void
           Controls how list labels are output to HTML, MHTML or EPUB. Default value is ExportListLabels.AUTO. The value of the property is ExportListLabels integer constant.
booleangetExportOriginalUrlForLinkedImages()
void
           Specifies whether original URL should be used as the URL of the linked images. Default value is false.
booleangetExportPageMargins()
void
setExportPageMargins(booleanvalue)
           Specifies whether page margins is exported to HTML, MHTML or EPUB. Default is false.
booleangetExportPageSetup()
void
setExportPageSetup(booleanvalue)
           Specifies whether page setup is exported to HTML, MHTML or EPUB. Default is false.
booleangetExportRelativeFontSize()
void
           Specifies whether font sizes should be output in relative units when saving to HTML, MHTML or EPUB. Default is false.
booleangetExportRoundtripInformation()
void
           Specifies whether to write the roundtrip information when saving to HTML, MHTML or EPUB. Default value is true for HTML and false for MHTML and EPUB.
booleangetExportTextBoxAsSvg()
void
setExportTextBoxAsSvg(booleanvalue)
           Controls how textboxes represented by Shape are saved to HTML, MHTML or EPUB. Default value is false.
booleangetExportTextInputFormFieldAsText()
void
           Controls how text input form fields are saved to HTML or MHTML. Default value is false.
booleangetExportTocPageNumbers()
void
           Specifies whether to write page numbers to table of contents when saving HTML, MHTML and EPUB. Default value is false.
booleangetExportXhtmlTransitional()
void
           Specifies whether to write the DOCTYPE declaration when saving to HTML or MHTML. When true, writes a DOCTYPE declaration in the document prior to the root element. Default value is false. When saving to EPUB or HTML5 (HtmlVersion.HTML_5) the DOCTYPE declaration is always written.
intgetFontResourcesSubsettingSizeThreshold()
void
           Controls which font resources need subsetting when saving to HTML, MHTML or EPUB. Default is 0.
IFontSavingCallbackgetFontSavingCallback()
void
           Allows to control how fonts are saved when a document is saved to HTML, MHTML or EPUB.
java.lang.StringgetFontsFolder()
void
setFontsFolder(java.lang.Stringvalue)
           Specifies the physical folder where fonts are saved when exporting a document to HTML. Default is an empty string.
java.lang.StringgetFontsFolderAlias()
void
setFontsFolderAlias(java.lang.Stringvalue)
           Specifies the name of the folder used to construct font URIs written into an HTML document. Default is an empty string.
intgetHtmlVersion()
void
setHtmlVersion(intvalue)
           Specifies version of HTML standard that should be used when saving the document to HTML or MHTML. Default value is HtmlVersion.XHTML. The value of the property is HtmlVersion integer constant.
intgetImageResolution()
void
           Specifies the output resolution for images when exporting to HTML, MHTML or EPUB. Default is 96 dpi.
IImageSavingCallbackgetImageSavingCallback()
void
           Allows to control how images are saved when a document is saved to HTML, MHTML or EPUB.
java.lang.StringgetImagesFolder()
void
setImagesFolder(java.lang.Stringvalue)
           Specifies the physical folder where images are saved when exporting a document to HTML format. Default is an empty string.
java.lang.StringgetImagesFolderAlias()
void
setImagesFolderAlias(java.lang.Stringvalue)
           Specifies the name of the folder used to construct image URIs written into an HTML document. Default is an empty string.
booleangetMemoryOptimization()
void
setMemoryOptimization(booleanvalue)
           Gets or sets value determining if memory optimization should be performed before saving the document. Default value for this property is false.
intgetMetafileFormat()
void
           Specifies in what format metafiles are saved when exporting to HTML, MHTML, or EPUB. Default value is HtmlMetafileFormat.PNG, meaning that metafiles are rendered to raster PNG images. The value of the property is HtmlMetafileFormat integer constant.
intgetOfficeMathOutputMode()
void
           Controls how OfficeMath objects are exported to HTML, MHTML or EPUB. Default value is HtmlOfficeMathOutputMode.Image. The value of the property is HtmlOfficeMathOutputMode integer constant.
booleangetPrettyFormat()
void
setPrettyFormat(booleanvalue)
           When true, pretty formats output where applicable. Default value is false.
booleangetResolveFontNames()
void
setResolveFontNames(booleanvalue)
           Specifies whether font family names used in the document are resolved and substituted according to Document.FontSettings when being written into HTML-based formats.
java.lang.StringgetResourceFolder()
void
setResourceFolder(java.lang.Stringvalue)
           Specifies a physical folder where all resources like images, fonts, and external CSS are saved when a document is exported to HTML. Default is an empty string.
java.lang.StringgetResourceFolderAlias()
void
setResourceFolderAlias(java.lang.Stringvalue)
           Specifies the name of the folder used to construct URIs of all resources written into an HTML document. Default is an empty string.
intgetSaveFormat()
void
setSaveFormat(intvalue)
           Specifies the format in which the document will be saved if this save options object is used. Can be SaveFormat.HTML, SaveFormat.MHTML or SaveFormat.EPUB. The value of the property is SaveFormat integer constant.
booleangetScaleImageToShapeSize()
void
           Specifies whether images are scaled by Aspose.Words to the bounding shape size when exporting to HTML, MHTML or EPUB. Default value is true.
intgetTableWidthOutputMode()
void
           Controls how table, row and cell widths are exported to HTML, MHTML or EPUB. Default value is HtmlElementSizeOutputMode.ALL. The value of the property is HtmlElementSizeOutputMode integer constant.
java.lang.StringgetTempFolder()
void
setTempFolder(java.lang.Stringvalue)
           Specifies the folder for temporary files used when saving to a DOC or DOCX file. By default this property is null and no temporary files are used.
booleangetUpdateFields()
void
setUpdateFields(booleanvalue)
           Gets or sets a value determining if fields of certain types should be updated before saving the document to a fixed page format. Default value for this property is true.
booleangetUpdateLastSavedTimeProperty()
void
           Gets or sets a value determining whether the BuiltInDocumentProperties.LastSavedTime property is updated before saving.
booleangetUpdateSdtContent()
void
setUpdateSdtContent(booleanvalue)
           Gets or sets value determining whether content of StructuredDocumentTag is updated before saving.
booleangetUseAntiAliasing()
void
setUseAntiAliasing(booleanvalue)
           Gets or sets a value determining whether or not to use anti-aliasing for rendering.
booleangetUseHighQualityRendering()
void
           Gets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms.
 

    • Constructor Detail

      • HtmlSaveOptions

        public HtmlSaveOptions()
        Initializes a new instance of this class that can be used to save a document in the SaveFormat.HTML format.

        Example:

        Converts a document to EPUB with save options specified.
        // Open an existing document from disk.
        Document doc = new Document(getMyDir() + "Document.EpubConversion.doc");
        
        // Create a new instance of HtmlSaveOptions. This object allows us to set options that control
        // how the output document is saved.
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        
        // Specify the desired encoding.
        saveOptions.setEncoding(Charset.forName("UTF-8"));
        
        // Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
        // which allows you to limit the size of each HTML part. This is useful for readers which cannot read
        // HTML files greater than a certain size e.g 300kb.
        saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
        
        // Specify that we want to export document properties.
        saveOptions.setExportDocumentProperties(true);
        
        // Specify that we want to save in EPUB format.
        saveOptions.setSaveFormat(SaveFormat.EPUB);
        
        // Export the document as an EPUB file.
        doc.save(getArtifactsDir() + "Document.EpubConversion.epub", saveOptions);
      • HtmlSaveOptions

        public HtmlSaveOptions(int saveFormat)
        Initializes a new instance of this class that can be used to save a document in the SaveFormat.HTML, SaveFormat.MHTML or SaveFormat.EPUB format.
        Parameters:
        saveFormat - A SaveFormat value. Can be SaveFormat.HTML, SaveFormat.MHTML or SaveFormat.EPUB.

        Example:

        Shows how to set a saved .html document to a specific version.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // Save the document to a .html file of the XHTML 1.0 Transitional standard
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
        {
            options.setHtmlVersion(com.aspose.words.HtmlVersion.XHTML);
            options.setExportXhtmlTransitional(true);
            options.setPrettyFormat(true);
        }
        
        // The DOCTYPE declaration at the top of this document will indicate the html version we chose
        doc.save(getArtifactsDir() + "HtmlSaveOptions.HtmlVersion.html", options);
    • Property Getters/Setters Detail

      • getAllowNegativeIndent/setAllowNegativeIndent

        public boolean getAllowNegativeIndent() / public void setAllowNegativeIndent(boolean value)
        
        Specifies whether negative left and right indents of paragraphs are normalized when saving to HTML, MHTML or EPUB. Default value is false.

        When negative indent is not allowed, it is exported as zero margin to HTML. When negative indent is allowed, a paragraph might appear partially outside of the browser window.

        Example:

        Shows how to preserve negative indents in the output .html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a table and give it a negative value for its indent, effectively pushing it out of the left page boundary
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1");
        builder.insertCell();
        builder.write("Cell 2");
        builder.endTable();
        table.setLeftIndent(-36);
        table.setPreferredWidth(PreferredWidth.fromPoints(144.0));
        
        // When saving to .html, this indent will only be preserved if we set this flag
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
        options.setAllowNegativeIndent(true);
        options.setTableWidthOutputMode(HtmlElementSizeOutputMode.RELATIVE_ONLY);
        
        // The first cell with "Cell 1" will not be visible in the output
        doc.save(getArtifactsDir() + "HtmlSaveOptions.AllowNegativeIndent.html", options);
      • getColorMode/setColorMode

        public int getColorMode() / public void setColorMode(int value)
        
        Gets or sets a value determining how colors are rendered. The value of the property is ColorMode integer constant.The default value is ColorMode.NORMAL.

        This property is used when the document is exported to fixed page formats.

        Example:

        Shows how change image color with save options property
        // Open document with color image
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // Set grayscale mode for document
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.setColorMode(ColorMode.GRAYSCALE);
        
        // Assert that color image in document was grey
        doc.save(getArtifactsDir() + "ColorMode.PdfGrayscaleMode.pdf", pdfSaveOptions);
      • getCssClassNamePrefix/setCssClassNamePrefix

        public java.lang.String getCssClassNamePrefix() / public void setCssClassNamePrefix(java.lang.String value)
        
        Specifies a prefix which is added to all CSS class names. Default value is an empty string and generated CSS class names have no common prefix.

        If this value is not empty, all CSS classes generated by Aspose.Words will start with the specified prefix. This might be useful, for example, if you add custom CSS to generated documents and want to prevent class name conflicts.

        If the value is not null or empty, it must be a valid CSS identifier.

        Example:

        Shows how to specifies a prefix which is added to all CSS class names
        Document doc = new Document(getMyDir() + "HtmlSaveOptions.CssClassNamePrefix.docx");
        
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        saveOptions.setCssStyleSheetType(CssStyleSheetType.EMBEDDED);
        saveOptions.setCssClassNamePrefix("aspose-");
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.CssClassNamePrefix.html", saveOptions);
      • getCssSavingCallback/setCssSavingCallback

        public ICssSavingCallback getCssSavingCallback() / public void setCssSavingCallback(ICssSavingCallback value)
        
        Allows to control how CSS styles are saved when a document is saved to HTML, MHTML or EPUB.

        Example:

        Shows how to work with CSS stylesheets that may be created along with Html documents.
        public void cssSavingCallback() throws Exception {
            // Open a document to be converted to html
            Document doc = new Document(getMyDir() + "Rendering.doc");
        
            // If our output document will produce a CSS stylesheet, we can use an HtmlSaveOptions to control where it is saved
            HtmlSaveOptions options = new HtmlSaveOptions();
        
            // By default, a CSS stylesheet is stored inside its HTML document, but we can have it saved to a separate file
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
        
            // We can designate a filename for our stylesheet like this
            options.setCssStyleSheetFileName(getArtifactsDir() + "Rendering.CssSavingCallback.css");
        
            // A custom ICssSavingCallback implementation can also control where that stylesheet will be saved and linked to by the Html document
            // This callback will override the filename we specified above in options.CssStyleSheetFileName,
            // but will give us more control over the saving process
            options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "Rendering.CssSavingCallback.css", true, false));
        
            // The CssSaving() method of our callback will be called at this stage
            doc.save(getArtifactsDir() + "Rendering.CssSavingCallback.html", options);
        }
        
        /// <summary>
        /// Designates a filename and other parameters for the saving of a CSS stylesheet
        /// </summary>
        private static class CustomCssSavingCallback implements ICssSavingCallback {
            public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) {
                mCssTextFileName = cssDocFilename;
                mIsExportNeeded = isExportNeeded;
                mKeepCssStreamOpen = keepCssStreamOpen;
            }
        
            public void cssSaving(CssSavingArgs args) throws Exception {
                Assert.assertNull(args.getCssStream());
                // Set up the stream that will create the CSS document
                args.setCssStream(new FileOutputStream(mCssTextFileName));
                Assert.assertNotNull(args.getCssStream());
                args.isExportNeeded(mIsExportNeeded);
                args.setKeepCssStreamOpen(mKeepCssStreamOpen);
        
                // We can also access the original document here like this
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
            }
        
            private String mCssTextFileName;
            private boolean mIsExportNeeded;
            private boolean mKeepCssStreamOpen;
        }
      • getCssStyleSheetFileName/setCssStyleSheetFileName

        public java.lang.String getCssStyleSheetFileName() / public void setCssStyleSheetFileName(java.lang.String value)
        
        Specifies the path and the name of the Cascading Style Sheet (CSS) file written when a document is exported to HTML. Default is an empty string.

        This property has effect only when saving a document to HTML format and external CSS style sheet is requested using CssStyleSheetType.

        If this property is empty, the CSS file will be saved into the same folder and with the same name as the HTML document but with the ".css" extension.

        If only path but no file name is specified in this property, the CSS file will be saved into the specified folder and will have the same name as the HTML document but with the ".css" extension.

        If the folder specified by this property doesn't exist, it will be created automatically before the CSS file is saved.

        Another way to specify a folder where external CSS file is saved is to use ResourceFolder.

        Example:

        Shows how to work with CSS stylesheets that may be created along with Html documents.
        public void cssSavingCallback() throws Exception {
            // Open a document to be converted to html
            Document doc = new Document(getMyDir() + "Rendering.doc");
        
            // If our output document will produce a CSS stylesheet, we can use an HtmlSaveOptions to control where it is saved
            HtmlSaveOptions options = new HtmlSaveOptions();
        
            // By default, a CSS stylesheet is stored inside its HTML document, but we can have it saved to a separate file
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
        
            // We can designate a filename for our stylesheet like this
            options.setCssStyleSheetFileName(getArtifactsDir() + "Rendering.CssSavingCallback.css");
        
            // A custom ICssSavingCallback implementation can also control where that stylesheet will be saved and linked to by the Html document
            // This callback will override the filename we specified above in options.CssStyleSheetFileName,
            // but will give us more control over the saving process
            options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "Rendering.CssSavingCallback.css", true, false));
        
            // The CssSaving() method of our callback will be called at this stage
            doc.save(getArtifactsDir() + "Rendering.CssSavingCallback.html", options);
        }
        
        /// <summary>
        /// Designates a filename and other parameters for the saving of a CSS stylesheet
        /// </summary>
        private static class CustomCssSavingCallback implements ICssSavingCallback {
            public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) {
                mCssTextFileName = cssDocFilename;
                mIsExportNeeded = isExportNeeded;
                mKeepCssStreamOpen = keepCssStreamOpen;
            }
        
            public void cssSaving(CssSavingArgs args) throws Exception {
                Assert.assertNull(args.getCssStream());
                // Set up the stream that will create the CSS document
                args.setCssStream(new FileOutputStream(mCssTextFileName));
                Assert.assertNotNull(args.getCssStream());
                args.isExportNeeded(mIsExportNeeded);
                args.setKeepCssStreamOpen(mKeepCssStreamOpen);
        
                // We can also access the original document here like this
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
            }
        
            private String mCssTextFileName;
            private boolean mIsExportNeeded;
            private boolean mKeepCssStreamOpen;
        }
        See Also:
        ResourceFolder, ResourceFolderAlias, CssStyleSheetType
      • getCssStyleSheetType/setCssStyleSheetType

        public int getCssStyleSheetType() / public void setCssStyleSheetType(int value)
        
        Specifies how CSS (Cascading Style Sheet) styles are exported to HTML, MHTML or EPUB. Default value is CssStyleSheetType.INLINE for HTML/MHTML and CssStyleSheetType.EXTERNAL for EPUB. The value of the property is CssStyleSheetType integer constant.

        Saving CSS style sheet into an external file is only supported when saving to HTML. When you are exporting to one of the container formats (EPUB or MHTML) and specifying CssStyleSheetType.EXTERNAL, CSS file will be encapsulated into the output package.

        Example:

        Shows how to work with CSS stylesheets that may be created along with Html documents.
        public void cssSavingCallback() throws Exception {
            // Open a document to be converted to html
            Document doc = new Document(getMyDir() + "Rendering.doc");
        
            // If our output document will produce a CSS stylesheet, we can use an HtmlSaveOptions to control where it is saved
            HtmlSaveOptions options = new HtmlSaveOptions();
        
            // By default, a CSS stylesheet is stored inside its HTML document, but we can have it saved to a separate file
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
        
            // We can designate a filename for our stylesheet like this
            options.setCssStyleSheetFileName(getArtifactsDir() + "Rendering.CssSavingCallback.css");
        
            // A custom ICssSavingCallback implementation can also control where that stylesheet will be saved and linked to by the Html document
            // This callback will override the filename we specified above in options.CssStyleSheetFileName,
            // but will give us more control over the saving process
            options.setCssSavingCallback(new CustomCssSavingCallback(getArtifactsDir() + "Rendering.CssSavingCallback.css", true, false));
        
            // The CssSaving() method of our callback will be called at this stage
            doc.save(getArtifactsDir() + "Rendering.CssSavingCallback.html", options);
        }
        
        /// <summary>
        /// Designates a filename and other parameters for the saving of a CSS stylesheet
        /// </summary>
        private static class CustomCssSavingCallback implements ICssSavingCallback {
            public CustomCssSavingCallback(String cssDocFilename, boolean isExportNeeded, boolean keepCssStreamOpen) {
                mCssTextFileName = cssDocFilename;
                mIsExportNeeded = isExportNeeded;
                mKeepCssStreamOpen = keepCssStreamOpen;
            }
        
            public void cssSaving(CssSavingArgs args) throws Exception {
                Assert.assertNull(args.getCssStream());
                // Set up the stream that will create the CSS document
                args.setCssStream(new FileOutputStream(mCssTextFileName));
                Assert.assertNotNull(args.getCssStream());
                args.isExportNeeded(mIsExportNeeded);
                args.setKeepCssStreamOpen(mKeepCssStreamOpen);
        
                // We can also access the original document here like this
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
            }
        
            private String mCssTextFileName;
            private boolean mIsExportNeeded;
            private boolean mKeepCssStreamOpen;
        }
        See Also:
        CssStyleSheetFileName
      • getDefaultTemplate/setDefaultTemplate

        public java.lang.String getDefaultTemplate() / public void setDefaultTemplate(java.lang.String value)
        
        Gets or sets path to default template (including filename). Default value for this property is empty string. If specified, this path is used to load template when Document.AutomaticallyUpdateSyles is true, but Document.AttachedTemplate is empty.

        Example:

        Shows how to set a default .docx document template.
        Document doc = new Document();
        
        // If we set this flag to true while not having a template attached to the document,
        // there will be no effect because there is no template document to draw style changes from
        doc.setAutomaticallyUpdateSyles(true);
        Assert.assertTrue(doc.getAttachedTemplate().isEmpty());
        
        // We can set a default template document filename in a SaveOptions object to make it apply to
        // all documents we save with it that have no AttachedTemplate value
        SaveOptions options = SaveOptions.createSaveOptions("Document.DefaultTemplate.docx");
        options.setDefaultTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dotx");
        
        doc.save(getArtifactsDir() + "Document.DefaultTemplate.docx", options);
      • getDmlEffectsRenderingMode/setDmlEffectsRenderingMode

        public int getDmlEffectsRenderingMode() / public void setDmlEffectsRenderingMode(int value)
        
        Gets or sets a value determining how DrawingML effects are rendered. The value of the property is DmlEffectsRenderingMode integer constant. The default value is DmlEffectsRenderingMode.SIMPLIFIED.

        This property is used when the document is exported to fixed page formats.

        Example:

        Shows how to export custom properties while saving to .pdf.
        Document doc = new Document();
        
        // Add a custom document property that doesn't use the name of some built in properties
        doc.getCustomDocumentProperties().add("Company", "My value");
        
        // Configure the PdfSaveOptions like this will display the properties
        // in the "Document Properties" menu of Adobe Acrobat Pro
        PdfSaveOptions options = new PdfSaveOptions();
        options.setCustomPropertiesExport(PdfCustomPropertiesExport.STANDARD);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.CustomPropertiesExport.pdf", options);
      • getDmlRenderingMode/setDmlRenderingMode

        public int getDmlRenderingMode() / public void setDmlRenderingMode(int value)
        
        Gets or sets a value determining how DrawingML shapes are rendered. The value of the property is DmlRenderingMode integer constant. The default value is DmlRenderingMode.FALLBACK.

        This property is used when the document is exported to fixed page formats.

        Example:

        Shows how to define rendering for DML shapes
        Document doc = DocumentHelper.createDocumentFillWithDummyText();
        
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.setDmlRenderingMode(DmlRenderingMode.DRAWING_ML);
        
        doc.save(getArtifactsDir() + "DrawingMl.pdf", pdfSaveOptions);

        Example:

        Shows how to configure DrawingML rendering quality with PdfSaveOptions.
        Document doc = new Document(getMyDir() + "DrawingMLEffects.docx");
        
        // Creating a new PdfSaveOptions object and setting its DmlEffectsRenderingMode to "None" will
        // strip the shapes of all their shading effects in the output pdf
        PdfSaveOptions options = new PdfSaveOptions();
        options.setDmlEffectsRenderingMode(DmlEffectsRenderingMode.NONE);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.DrawingML.pdf", options);
      • getDocumentPartSavingCallback/setDocumentPartSavingCallback

        public IDocumentPartSavingCallback getDocumentPartSavingCallback() / public void setDocumentPartSavingCallback(IDocumentPartSavingCallback value)
        
        Allows to control how document parts are saved when a document is saved to HTML or EPUB.

        Example:

        Shows how split a document into parts and save them.
        public void documentParts() throws Exception {
            // Open a document to be converted to html
            Document doc = new Document(getMyDir() + "Rendering.doc");
            String outFileName = "SavingCallback.DocumentParts.Rendering.html";
        
            // We can use an appropriate SaveOptions subclass to customize the conversion process
            HtmlSaveOptions options = new HtmlSaveOptions();
        
            // We can use it to split a document into smaller parts, in this instance split by section breaks
            // Each part will be saved into a separate file, creating many files during the conversion process instead of just one
            options.setDocumentSplitCriteria(DocumentSplitCriteria.SECTION_BREAK);
        
            // We can set a callback to name each document part file ourselves
            options.setDocumentPartSavingCallback(new SavedDocumentPartRename(outFileName, options.getDocumentSplitCriteria()));
        
            // If we convert a document that contains images into html, we will end up with one html file which links to several images
            // Each image will be in the form of a file in the local file system
            // There is also a callback that can customize the name and file system location of each image
            options.setImageSavingCallback(new SavedImageRename(outFileName));
        
            // The DocumentPartSaving() and ImageSaving() methods of our callbacks will be run at this time
            doc.save(getArtifactsDir() + outFileName, options);
        }
        
        /// <summary>
        /// Renames saved document parts that are produced when an HTML document is saved while being split according to a criteria
        /// </summary>
        private static class SavedDocumentPartRename implements IDocumentPartSavingCallback {
            public SavedDocumentPartRename(String outFileName, int documentSplitCriteria) {
                mOutFileName = outFileName;
                mDocumentSplitCriteria = documentSplitCriteria;
            }
        
            public void documentPartSaving(DocumentPartSavingArgs args) throws Exception {
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
        
                String partType = "";
        
                switch (mDocumentSplitCriteria) {
                    case DocumentSplitCriteria.PAGE_BREAK:
                        partType = "Page";
                        break;
                    case DocumentSplitCriteria.COLUMN_BREAK:
                        partType = "Column";
                        break;
                    case DocumentSplitCriteria.SECTION_BREAK:
                        partType = "Section";
                        break;
                    case DocumentSplitCriteria.HEADING_PARAGRAPH:
                        partType = "Paragraph from heading";
                        break;
                }
        
                String partFileName = MessageFormat.format("{0} part {1}, of type {2}.{3}", mOutFileName, ++mCount, partType, FilenameUtils.getExtension(args.getDocumentPartFileName()));
        
                // We can designate the filename and location of each output file either by filename
                args.setDocumentPartFileName(partFileName);
        
                // Or we can make a new stream and choose the location of the file at construction
                try {
                    FileOutputStream outputStream = new FileOutputStream(getArtifactsDir() + partFileName);
                    args.setDocumentPartStream(outputStream);
                } catch (IOException e) {
                    e.printStackTrace();
                }
        
                Assert.assertNotNull(args.getDocumentPartStream());
                Assert.assertFalse(args.getKeepDocumentPartStreamOpen());
            }
        
            private int mCount;
            private String mOutFileName;
            private int mDocumentSplitCriteria;
        }
        
        /// <summary>
        /// Renames saved images that are produced when an HTML document is saved
        /// </summary>
        public static class SavedImageRename implements IImageSavingCallback {
            public SavedImageRename(String outFileName) {
                mOutFileName = outFileName;
            }
        
            public void imageSaving(ImageSavingArgs args) throws Exception {
                // Same filename and stream functions as above in IDocumentPartSavingCallback apply here
                String imageFileName = MessageFormat.format("{0} shape {1}, of type {2}.{3}", mOutFileName, ++mCount, args.getCurrentShape().getShapeType(), FilenameUtils.getExtension(args.getImageFileName()));
        
                args.setImageFileName(imageFileName);
        
                try {
                    FileOutputStream outputStream = new FileOutputStream(getArtifactsDir() + imageFileName);
                    args.setImageStream(outputStream);
                } catch (IOException e) {
                    e.printStackTrace();
                }
        
                Assert.assertNotNull(args.getImageStream());
                Assert.assertTrue(args.isImageAvailable());
                Assert.assertFalse(args.getKeepImageStreamOpen());
            }
        
            private int mCount;
            private String mOutFileName;
        }
      • getDocumentSplitCriteria/setDocumentSplitCriteria

        public int getDocumentSplitCriteria() / public void setDocumentSplitCriteria(int value)
        
        Specifies how the document should be split when saving to SaveFormat.HTML or SaveFormat.EPUB format. Default is DocumentSplitCriteria.NONE for HTML and DocumentSplitCriteria.HEADING_PARAGRAPH for EPUB. The value of the property is DocumentSplitCriteria integer constant.

        Normally you would want a document saved to HTML as a single file. But in some cases it is preferable to split the output into several smaller HTML pages. When saving to HTML format these pages will be output to individual files or streams. When saving to EPUB format they will be incorporated into corresponding packages.

        A document cannot be split when saving in the MHTML format.

        Example:

        Converts a document to EPUB with save options specified.
        // Open an existing document from disk.
        Document doc = new Document(getMyDir() + "Document.EpubConversion.doc");
        
        // Create a new instance of HtmlSaveOptions. This object allows us to set options that control
        // how the output document is saved.
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        
        // Specify the desired encoding.
        saveOptions.setEncoding(Charset.forName("UTF-8"));
        
        // Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
        // which allows you to limit the size of each HTML part. This is useful for readers which cannot read
        // HTML files greater than a certain size e.g 300kb.
        saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
        
        // Specify that we want to export document properties.
        saveOptions.setExportDocumentProperties(true);
        
        // Specify that we want to save in EPUB format.
        saveOptions.setSaveFormat(SaveFormat.EPUB);
        
        // Export the document as an EPUB file.
        doc.save(getArtifactsDir() + "Document.EpubConversion.epub", saveOptions);
        See Also:
        DocumentSplitHeadingLevel, DocumentPartSavingCallback
      • getDocumentSplitHeadingLevel/setDocumentSplitHeadingLevel

        public int getDocumentSplitHeadingLevel() / public void setDocumentSplitHeadingLevel(int value)
        
        Specifies the maximum level of headings at which to split the document. Default value is 2.

        When DocumentSplitCriteria includes DocumentSplitCriteria.HEADING_PARAGRAPH and this property is set to a value from 1 to 9, the document will be split at paragraphs formatted using Heading 1, Heading 2 , Heading 3 etc. styles up to the specified heading level.

        By default, only Heading 1 and Heading 2 paragraphs cause the document to be split. Setting this property to zero will cause the document not to be split at heading paragraphs at all.

        Example:

        Shows how to split a document into several html documents by heading levels.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert headings of levels 1 - 3
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 1"));
        builder.writeln("Heading #1");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 2"));
        builder.writeln("Heading #2");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 3"));
        builder.writeln("Heading #3");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 1"));
        builder.writeln("Heading #4");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 2"));
        builder.writeln("Heading #5");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 3"));
        builder.writeln("Heading #6");
        
        // Create a HtmlSaveOptions object and set the split criteria to "HeadingParagraph", meaning that the document
        // will be split into parts at the beginning of every paragraph of a "Heading" style, and each part will be saved as a separate document
        // Also, we will set the DocumentSplitHeadingLevel to 2, which will split the document only at headings that have levels from 1 to 2
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
            options.setDocumentSplitHeadingLevel(2);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.HeadingLevels.html", options);
        See Also:
        DocumentSplitCriteria, DocumentPartSavingCallback
      • getEncoding/setEncoding

        public java.nio.charset.Charset getEncoding() / public void setEncoding(java.nio.charset.Charset value)
        
        Specifies the encoding to use when exporting to HTML, MHTML or EPUB. Default value is 'UTF-8' Charset.

        Example:

        Converts a document to EPUB with save options specified.
        // Open an existing document from disk.
        Document doc = new Document(getMyDir() + "Document.EpubConversion.doc");
        
        // Create a new instance of HtmlSaveOptions. This object allows us to set options that control
        // how the output document is saved.
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        
        // Specify the desired encoding.
        saveOptions.setEncoding(Charset.forName("UTF-8"));
        
        // Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
        // which allows you to limit the size of each HTML part. This is useful for readers which cannot read
        // HTML files greater than a certain size e.g 300kb.
        saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
        
        // Specify that we want to export document properties.
        saveOptions.setExportDocumentProperties(true);
        
        // Specify that we want to save in EPUB format.
        saveOptions.setSaveFormat(SaveFormat.EPUB);
        
        // Export the document as an EPUB file.
        doc.save(getArtifactsDir() + "Document.EpubConversion.epub", saveOptions);
      • getEpubNavigationMapLevel/setEpubNavigationMapLevel

        public int getEpubNavigationMapLevel() / public void setEpubNavigationMapLevel(int value)
        
        Specifies the maximum level of headings populated to the navigation map when exporting to IDPF EPUB format. Default value is 3.

        Navigation map in IDPF EPUB format allows user agents to provide easy way of navigation through the document structure. Usually navigation points correspond to headings in the document. To populate headings up to level N assign this value to EpubNavigationMapLevel.

        By default, three levels of headings are populated: paragraphs of styles Heading 1, Heading 2 and Heading 3. You can set this property to a value from 1 to 9 to request corresponding maximum level. Setting it to zero will reduce navigation map to only document root or roots of document parts.

        Example:

        Shows the relationship between heading levels and the Epub navigation panel.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert headings of levels 1 - 3
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 1"));
        builder.writeln("Heading #1");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 2"));
        builder.writeln("Heading #2");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 3"));
        builder.writeln("Heading #3");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 1"));
        builder.writeln("Heading #4");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 2"));
        builder.writeln("Heading #5");
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 3"));
        builder.writeln("Heading #6");
        
        // Epub readers normally treat paragraphs with "Heading" styles as anchors for a table of contents-style navigation pane
        // We set a maximum heading level above which headings won't be registered by the reader as navigation points with
        // a HtmlSaveOptions object and its EpubNavigationLevel attribute
        // Our document has headings of levels 1 to 3,
        // but our output epub will only place level 1 and 2 headings in the table of contents
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.EPUB);
        options.setEpubNavigationMapLevel(2);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.EpubHeadings.epub", options);
      • getExportCidUrlsForMhtmlResources/setExportCidUrlsForMhtmlResources

        public boolean getExportCidUrlsForMhtmlResources() / public void setExportCidUrlsForMhtmlResources(boolean value)
        
        Specifies whether to use CID (Content-ID) URLs to reference resources (images, fonts, CSS) included in MHTML documents. Default value is false.

        This option affects only documents being saved to MHTML.

        By default, resources in MHTML documents are referenced by file name (for example, "image.png"), which are matched against "Content-Location" headers of MIME parts.

        This option enables an alternative method, where references to resource files are written as CID (Content-ID) URLs (for example, "cid:image.png") and are matched against "Content-ID" headers.

        In theory, there should be no difference between the two referencing methods and either of them should work fine in any browser or mail agent. In practice, however, some agents fail to fetch resources by file name. If your browser or mail agent refuses to load resources included in an MTHML document (doesn't show images or doesn't load CSS styles), try exporting the document with CID URLs.

        Example:

        Shows how to enable content IDs for output MHTML documents.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // Setting this flag will replace "Content-Location" tags with "Content-ID" tags for each resource from the input document
        // The file names that were next to each "Content-Location" tag are re-purposed as content IDs
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.MHTML);
        {
            options.setExportCidUrlsForMhtmlResources(true);
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setPrettyFormat(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ContentIdUrls.mht", options);
      • getExportDocumentProperties/setExportDocumentProperties

        public boolean getExportDocumentProperties() / public void setExportDocumentProperties(boolean value)
        
        Specifies whether to export built-in and custom document properties to HTML, MHTML or EPUB. Default value is false.

        Example:

        Converts a document to EPUB with save options specified.
        // Open an existing document from disk.
        Document doc = new Document(getMyDir() + "Document.EpubConversion.doc");
        
        // Create a new instance of HtmlSaveOptions. This object allows us to set options that control
        // how the output document is saved.
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        
        // Specify the desired encoding.
        saveOptions.setEncoding(Charset.forName("UTF-8"));
        
        // Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
        // which allows you to limit the size of each HTML part. This is useful for readers which cannot read
        // HTML files greater than a certain size e.g 300kb.
        saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
        
        // Specify that we want to export document properties.
        saveOptions.setExportDocumentProperties(true);
        
        // Specify that we want to save in EPUB format.
        saveOptions.setSaveFormat(SaveFormat.EPUB);
        
        // Export the document as an EPUB file.
        doc.save(getArtifactsDir() + "Document.EpubConversion.epub", saveOptions);
      • getExportDropDownFormFieldAsText/setExportDropDownFormFieldAsText

        public boolean getExportDropDownFormFieldAsText() / public void setExportDropDownFormFieldAsText(boolean value)
        
        Controls how drop-down form fields are saved to HTML or MHTML. Default value is false.

        When set to true, exports drop-down form fields as normal text. When false, exports drop-down form fields as SELECT element in HTML.

        When exporting to EPUB, text drop-down form fields are always saved as text due to requirements of this format.

        Example:

        Shows how to get drop down combo box form fields to blend in with paragraph text when saving to html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use a document builder to insert a combo box with the value "Two" selected
        builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 1);
        
        // When converting to .html, drop down combo boxes will be converted to select/option tags to preserve their functionality
        // If we want to freeze a combo box at its current selected value and convert it into plain text, we can do so with this flag
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setExportDropDownFormFieldAsText(true);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.DropDownFormField.html", options);
      • getExportFontResources/setExportFontResources

        public boolean getExportFontResources() / public void setExportFontResources(boolean value)
        
        Specifies whether font resources should be exported to HTML, MHTML or EPUB. Default is false.

        Exporting font resources allows for consistent document rendering independent of the fonts available in a given user's environment.

        If ExportFontResources is set to true, main HTML document will refer to every font via the CSS 3 @font-face at-rule and fonts will be output as separate files. When exporting to IDPF EPUB or MHTML formats, fonts will be embedded into the corresponding package along with other subsidiary files.

        If ExportFontsAsBase64 is set to true, fonts will not be saved to separate files. Instead, they will be embedded into @font-face at-rules in Base64 encoding.

        Important! When exporting font resources, font licensing issues should be considered. Authors who want to use specific fonts via a downloadable font mechanism must always carefully verify that their intended use is within the scope of the font license. Many commercial fonts presently do not allow web downloading of their fonts in any form. License agreements that cover some fonts specifically note that usage via @font-face rules in CSS style sheets is not allowed. Font subsetting can also violate license terms.

        Example:

        Shows how to define custom logic for handling font exporting when saving to HTML based formats.
        public void saveHtmlExportFonts() throws Exception {
            Document doc = new Document(getMyDir() + "Rendering.doc");
        
            // Set the option to export font resources.
            HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.MHTML);
            options.setExportFontResources(true);
            // Create and pass the object which implements the handler methods.
            options.setFontSavingCallback(new HandleFontSaving());
        
            doc.save(getArtifactsDir() + "Document.SaveWithFontsExport.html", options);
        }
        
        /// <summary>
        /// Prints information about fonts and saves them alongside their output .html
        /// </summary>
        public static class HandleFontSaving implements IFontSavingCallback {
            public void fontSaving(FontSavingArgs args) throws Exception {
                // Print information about fonts
                System.out.println(MessageFormat.format("Font:\t{0}", args.getFontFamilyName()));
                if (args.getBold()) System.out.println(", bold");
                if (args.getItalic()) System.out.println(", italic");
                System.out.println(MessageFormat.format("\nSource:\t{0}, {1} bytes\n", args.getOriginalFileName(), args.getOriginalFileSize()));
        
                Assert.assertTrue(args.isExportNeeded());
                Assert.assertTrue(args.isSubsettingNeeded());
        
                // We can designate where each font will be saved by either specifying a file name, or creating a new stream
                String[] parts = args.getOriginalFileName().split(File.separator + File.separator);
                String lastOne = parts[parts.length - 1];
                args.setFontFileName(lastOne);
        
                Assert.assertFalse(args.getKeepFontStreamOpen());
                // We can access the source document from here also
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
            }
        }
        See Also:
        FontResourcesSubsettingSizeThreshold
      • getExportFontsAsBase64/setExportFontsAsBase64

        public boolean getExportFontsAsBase64() / public void setExportFontsAsBase64(boolean value)
        
        Specifies whether fonts resources should be embedded to HTML in Base64 encoding. Default is false.

        By default, 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.

        Example:

        Shows how to save a .html document with resources embedded inside it.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // By default, when converting a document with images to .html, resources such as images will be linked to in external files
        // We can set these flags to embed resources inside the output .html instead, cutting down on the amount of files created during the conversion
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportFontsAsBase64(true);
            options.setExportImagesAsBase64(true);
            options.setPrettyFormat(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportBase64.html", options);
      • getExportHeadersFootersMode/setExportHeadersFootersMode

        public int getExportHeadersFootersMode() / public void setExportHeadersFootersMode(int value)
        
        Specifies how headers and footers are output to HTML, MHTML or EPUB. Default value is ExportHeadersFootersMode.PER_SECTION for HTML/MHTML and ExportHeadersFootersMode.NONE for EPUB. The value of the property is ExportHeadersFootersMode integer constant.

        It is hard to meaningfully output headers and footers to HTML because HTML is not paginated.

        When this property is ExportHeadersFootersMode.PER_SECTION, Aspose.Words exports only primary headers and footers at the beginning and the end of each section.

        When it is ExportHeadersFootersMode.FIRST_SECTION_HEADER_LAST_SECTION_FOOTER only first primary header and the last primary footer (including linked to previous) are exported.

        You can disable export of headers and footers altogether by setting this property to ExportHeadersFootersMode.NONE.

        Example:

        Demonstrates how to disable the export of headers and footers when saving to HTML based formats.
        Document doc = new Document(getMyDir() + "HeaderFooter.RemoveFooters.doc");
        
        // Disables exporting headers and footers.
        HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);
        saveOptions.setExportHeadersFootersMode(ExportHeadersFootersMode.NONE);
        
        doc.save(getArtifactsDir() + "HeaderFooter.DisableHeadersFooters.html", saveOptions);
      • getExportImagesAsBase64/setExportImagesAsBase64

        public boolean getExportImagesAsBase64() / public void setExportImagesAsBase64(boolean value)
        
        Specifies whether images are saved in Base64 format to HTML, MHTML or EPUB. Default is false.

        When this property is set to true image data is exported directly on the img elements and separate files are not created.

        Example:

        Shows how to save a .html document with resources embedded inside it.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // By default, when converting a document with images to .html, resources such as images will be linked to in external files
        // We can set these flags to embed resources inside the output .html instead, cutting down on the amount of files created during the conversion
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportFontsAsBase64(true);
            options.setExportImagesAsBase64(true);
            options.setPrettyFormat(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportBase64.html", options);
      • getExportLanguageInformation/setExportLanguageInformation

        public boolean getExportLanguageInformation() / public void setExportLanguageInformation(boolean value)
        
        Specifies whether language information is exported to HTML, MHTML or EPUB. Default is false.

        When this property is set to true Aspose.Words outputs lang HTML attribute on the document elements that specify language. This can be needed to preserve language related semantics.

        Example:

        Shows how to preserve language information when saving to .html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use the builder to write text in more than one language
        builder.getFont().setLocaleId(2057); // en-GB
        builder.writeln("Hello world!");
        
        builder.getFont().setLocaleId(1049); // ru-RU
        builder.write("Привет, мир!");
        
        // Normally, when saving a document with more than one proofing language to .html,
        // only the text content is preserved with no traces of any other languages
        // Saving with a HtmlSaveOptions object with this flag set will add "lang" attributes to spans
        // in places where other proofing languages were used
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportLanguageInformation(true);
            options.setPrettyFormat(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportLanguageInformation.html", options);
      • getExportListLabels/setExportListLabels

        public int getExportListLabels() / public void setExportListLabels(int value)
        
        Controls how list labels are output to HTML, MHTML or EPUB. Default value is ExportListLabels.AUTO. The value of the property is ExportListLabels integer constant.

        Example:

        Shows how to export an indented list to .html as plain text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use the builder to insert a list
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        builder.getListFormat().setList(list);
        
        builder.writeln("List item 1.");
        builder.getListFormat().listIndent();
        builder.writeln("List item 2.");
        builder.getListFormat().listIndent();
        builder.write("List item 3.");
        
        // When we save this to .html, normally our list will be represented by <li> tags
        // We can set this flag to have lists as plain text instead
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportListLabels(ExportListLabels.AS_INLINE_TEXT);
            options.setPrettyFormat(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.List.html", options);
      • getExportOriginalUrlForLinkedImages/setExportOriginalUrlForLinkedImages

        public boolean getExportOriginalUrlForLinkedImages() / public void setExportOriginalUrlForLinkedImages(boolean value)
        
        Specifies whether original URL should be used as the URL of the linked images. Default value is false.

        If value is set to trueImageData.SourceFullName value is used as the URL of linked images and linked images are not loaded into document's folder or ImagesFolder.

        If value is set to false linked images are loaded into document's folder or ImagesFolder and URL of each linked image is constructed depending on document's folder, ImagesFolder and ImagesFolderAlias properties.

        Example:

        Shows how to set folders and folder aliases for externally saved resources when saving to html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setImageResolution(72);
            options.setFontResourcesSubsettingSizeThreshold(0);
            options.setFontsFolder(getArtifactsDir() + "Fonts");
            options.setImagesFolder(getArtifactsDir() + "Images");
            options.setResourceFolder(getArtifactsDir() + "Resources");
            options.setFontsFolderAlias("http://example.com/fonts");
            options.setImagesFolderAlias("http://example.com/images");
            options.setResourceFolderAlias("http://example.com/resources");
            options.setExportOriginalUrlForLinkedImages(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FolderAlias.html", options);
      • getExportPageMargins/setExportPageMargins

        public boolean getExportPageMargins() / public void setExportPageMargins(boolean value)
        
        Specifies whether page margins is exported to HTML, MHTML or EPUB. Default is false. Aspose.Words does not show area of page margins by default. If any elements are completely or partially clipped by the document edge the displayed area can be extended with this option.

        Example:

        Shows how to show out-of-bounds objects in output .html documents.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use a builder to insert a shape with no wrapping
        Shape shape = builder.insertShape(ShapeType.CUBE, 200.0, 200.0);
        
        shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        shape.setWrapType(WrapType.NONE);
        
        // Negative values for shape position may cause the shape to go out of page bounds
        // If we export this to .html, the shape will be truncated
        shape.setLeft(-150);
        
        // We can avoid that and have the entire shape be visible by setting this flag
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setExportPageMargins(true);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportPageMargins.html", options);
      • getExportPageSetup/setExportPageSetup

        public boolean getExportPageSetup() / public void setExportPageSetup(boolean value)
        
        Specifies whether page setup is exported to HTML, MHTML or EPUB. Default is false.

        Each Section in Aspose.Words document model provides page setup information via PageSetup class. When you export a document to HTML format you might need to keep this information for further usage. In particular, page setup might be important for rendering to paged media (printing) or subsequent conversion to the native Microsoft Word file formats (DOCX, DOC, RTF, WML).

        In most cases HTML is intended for viewing in browsers where pagination is not performed. So this feature is inactive by default.

        Example:

        Shows how to preserve section structure/page setup information when saving to html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use a DocumentBuilder to insert two sections with text
        builder.writeln("Section 1");
        builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
        builder.writeln("Section 2");
        
        // Change dimensions and paper size of first section
        PageSetup pageSetup = doc.getSections().get(0).getPageSetup();
        pageSetup.setTopMargin(36.0);
        pageSetup.setBottomMargin(36.0);
        pageSetup.setPaperSize(PaperSize.A5);
        
        // Section structure and pagination are normally lost when when converting to .html
        // We can create an HtmlSaveOptions object with the ExportPageSetup flag set to true
        // to preserve the section structure in <div> tags and page dimensions in the output document's CSS
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportPageSetup(true);
            options.setPrettyFormat(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportPageSetup.html", options);
      • getExportRelativeFontSize/setExportRelativeFontSize

        public boolean getExportRelativeFontSize() / public void setExportRelativeFontSize(boolean value)
        
        Specifies whether font sizes should be output in relative units when saving to HTML, MHTML or EPUB. Default is false.

        In many existing documents (HTML, IDPF EPUB) font sizes are specified in relative units. This allows applications to adjust text size when viewing/processing documents. For instance, Microsoft Internet Explorer has "View->Text Size" submenu, Adobe Digital Editions has two buttons: Increase/Decrease Text Size. If you expect this functionality to work then set ExportRelativeFontSize property to true.

        Aspose Words document model contains and operates only with absolute font size units. Relative units need additional logic to be recalculated from some initial (standard) size. Font size of Normal document style is taken as standard. For instance, if Normal has 12pt font and some text is 18pt then it will be output as 1.5em. to the HTML.

        When this option is enabled, document elements other than text will still have absolute sizes. Also some text-related attributes might be expressed absolutely. In particular, line spacing specified with "exactly" rule might produce unwanted results when scaling text. So the source documents should be properly designed and tested when exporting with ExportRelativeFontSize set to true.

        Example:

        Shows how to use relative font sizes when saving to .html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use a builder to write some text in various sizes
        builder.writeln("Default font size, ");
        builder.getFont().setSize(24.0);
        builder.writeln("2x default font size,");
        builder.getFont().setSize(96.0);
        builder.write("8x default font size");
        
        // We can save font sizes as ratios of the default size, which will be 12 in this case
        // If we use an input .html, this size can be set with the AbsSize {font-size:12pt} tag
        // The ExportRelativeFontSize will enable this feature
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportRelativeFontSize(true);
            options.setPrettyFormat(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.RelativeFontSize.html", options);
      • getExportRoundtripInformation/setExportRoundtripInformation

        public boolean getExportRoundtripInformation() / public void setExportRoundtripInformation(boolean value)
        
        Specifies whether to write the roundtrip information when saving to HTML, MHTML or EPUB. Default value is true for HTML and false for MHTML and EPUB.

        Saving of the roundtrip information allows to restore document properties such as tab stops, comments, headers and footers during the HTML documents loading back into a Document object.

        When true, the roundtrip information is exported as -aw-* CSS properties of the corresponding HTML elements.

        When false, causes no roundtrip information to be output into produced files.

        Example:

        Shows how to preserve hidden elements when converting to .html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // When converting a document to .html, some elements such as hidden bookmarks, original shape positions,
        // or footnotes will be either removed or converted to plain text and effectively be lost
        // Saving with a HtmlSaveOptions object with ExportRoundtripInformation set to true will preserve these elements
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportRoundtripInformation(true);
            options.setPrettyFormat(true);
        }
        
        // These elements will have tags that will start with "-aw", such as "-aw-import" or "-aw-left-pos"
        doc.save(getArtifactsDir() + "HtmlSaveOptions.RoundTripInformation.html", options);
      • getExportTextBoxAsSvg/setExportTextBoxAsSvg

        public boolean getExportTextBoxAsSvg() / public void setExportTextBoxAsSvg(boolean value)
        
        Controls how textboxes represented by Shape are saved to HTML, MHTML or EPUB. Default value is false.

        When set to true, exports textboxes as inline <svg> elements. When false, exports as <img> elements.

        Example:

        Shows how to export text boxes as scalable vector graphics.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use a DocumentBuilder to insert a text box and give it some text content
        Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 60.0);
        builder.moveTo(textBox.getFirstParagraph());
        builder.write("My text box");
        
        // Normally, all shapes such as the text box we placed are exported to .html as external images linked by the .html document
        // We can save with an HtmlSaveOptions object with the ExportTextBoxAsSvg set to true to save text boxes as <svg> tags,
        // which will cause no linked images to be saved and will make the inner text selectable
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setExportTextBoxAsSvg(true);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportTextBox.html", options);
      • getExportTextInputFormFieldAsText/setExportTextInputFormFieldAsText

        public boolean getExportTextInputFormFieldAsText() / public void setExportTextInputFormFieldAsText(boolean value)
        
        Controls how text input form fields are saved to HTML or MHTML. Default value is false.

        When set to true, exports text input form fields as normal text. When false, exports Word text input form fields as INPUT elements in HTML.

        When exporting to EPUB, text input form fields are always saved as text due to requirements of this format.

        Example:

        Shows how to set save options before saving a document to HTML.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // This is the directory we want the exported images to be saved to.
        File imagesDir = new File(getMyDir(), "SaveHtmlWithOptions");
        
        // The folder specified needs to exist and should be empty.
        if (imagesDir.exists()) {
            imagesDir.delete();
        }
        
        imagesDir.mkdir();
        
        // Set an option to export form fields as plain text, not as HTML input elements.
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
        options.setExportTextInputFormFieldAsText(true);
        options.setImagesFolder(imagesDir.getPath());
        
        doc.save(getArtifactsDir() + "Document.SaveWithOptions.html", options);
      • getExportTocPageNumbers/setExportTocPageNumbers

        public boolean getExportTocPageNumbers() / public void setExportTocPageNumbers(boolean value)
        
        Specifies whether to write page numbers to table of contents when saving HTML, MHTML and EPUB. Default value is false.

        Example:

        Shows how to display page numbers when saving a document with a table of contents to .html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a table of contents
        FieldToc fieldToc = (FieldToc) builder.insertField(FieldType.FIELD_TOC, true);
        
        // Populate the document with paragraphs of a "Heading" style that the table of contents will pick up
        builder.getParagraphFormat().setStyle(builder.getDocument().getStyles().get("Heading 1"));
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Entry 1");
        builder.writeln("Entry 2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Entry 3");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Entry 4");
        
        // Our headings span several pages, and those page numbers will be displayed by the TOC at the top of the document
        fieldToc.updatePageNumbers();
        doc.updateFields();
        
        // These page numbers are normally omitted since .html has no pagination, but we can still have them displayed
        // if we save with a HtmlSaveOptions object with the ExportTocPageNumbers set to true
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setExportTocPageNumbers(true);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportTocPageNumbers.html", options);
      • getExportXhtmlTransitional/setExportXhtmlTransitional

        public boolean getExportXhtmlTransitional() / public void setExportXhtmlTransitional(boolean value)
        
        Specifies whether to write the DOCTYPE declaration when saving to HTML or MHTML. When true, writes a DOCTYPE declaration in the document prior to the root element. Default value is false. When saving to EPUB or HTML5 (HtmlVersion.HTML_5) the DOCTYPE declaration is always written.

        Aspose.Words always writes well formed HTML regardless of this setting.

        When true, the beginning of the HTML output document will look like this:

                    <?xml version="1.0" encoding="utf-8" standalone="no" ?>
                    <!DOCTYPE html 
                          PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                    

        Aspose.Words aims to output XHTML according to the XHTML 1.0 Transitional specification, but the output will not always validate against the DTD. Some structures inside a Microsoft Word document are hard or impossible to map to a document that will validate against the XHTML schema. For example, XHTML does not allow nested lists (UL cannot be nested inside another UL element), but in Microsoft Word document multilevel lists occur quite often.

        Example:

        Shows how to set a saved .html document to a specific version.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // Save the document to a .html file of the XHTML 1.0 Transitional standard
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
        {
            options.setHtmlVersion(com.aspose.words.HtmlVersion.XHTML);
            options.setExportXhtmlTransitional(true);
            options.setPrettyFormat(true);
        }
        
        // The DOCTYPE declaration at the top of this document will indicate the html version we chose
        doc.save(getArtifactsDir() + "HtmlSaveOptions.HtmlVersion.html", options);
      • getFontResourcesSubsettingSizeThreshold/setFontResourcesSubsettingSizeThreshold

        public int getFontResourcesSubsettingSizeThreshold() / public void setFontResourcesSubsettingSizeThreshold(int value)
        
        Controls which font resources need subsetting when saving to HTML, MHTML or EPUB. Default is 0.

        ExportFontResources allows exporting fonts as subsidiary files or as parts of the output package. If the document uses many fonts, especially with large number of glyphs, then output size can grow significantly. Font subsetting reduces the size of the exported font resource by filtering out glyphs that are not used by the current document.

        Font subsetting works as follows:

        • By default, all exported fonts are subsetted.
        • Setting FontResourcesSubsettingSizeThreshold to a positive value instructs Aspose.Words to subset fonts which file size is larger than the specified value.
        • Setting the property to java.lang.Integer.MAX_VALUE suppresses font subsetting.

        Important! When exporting font resources, font licensing issues should be considered. Authors who want to use specific fonts via a downloadable font mechanism must always carefully verify that their intended use is within the scope of the font license. Many commercial fonts presently do not allow web downloading of their fonts in any form. License agreements that cover some fonts specifically note that usage via @font-face rules in CSS style sheets is not allowed. Font subsetting can also violate license terms.

        Example:

        Shows how to work with font subsetting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Use a DocumentBuilder to insert text with several fonts
        builder.getFont().setName("Arial");
        builder.writeln("Hello world!");
        builder.getFont().setName("Times New Roman");
        builder.writeln("Hello world!");
        builder.getFont().setName("Courier New");
        builder.writeln("Hello world!");
        
        // When saving to .html, font subsetting fully applies by default, meaning that when we export fonts with our file,
        // the symbols not used by our document are not represented by the exported fonts, which cuts down file size dramatically
        // Font files of a file size larger than FontResourcesSubsettingSizeThreshold get subsetted, so a value of 0 will apply default full subsetting
        // Setting the value to something large will fully suppress subsetting, saving some very large font files that cover every glyph
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setExportFontResources(true);
            options.setFontResourcesSubsettingSizeThreshold(Integer.MAX_VALUE);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FontSubsetting.html", options);
        See Also:
        ExportFontResources
      • getFontSavingCallback/setFontSavingCallback

        public IFontSavingCallback getFontSavingCallback() / public void setFontSavingCallback(IFontSavingCallback value)
        
        Allows to control how fonts are saved when a document is saved to HTML, MHTML or EPUB.

        Example:

        Shows how to define custom logic for handling font exporting when saving to HTML based formats.
        public void saveHtmlExportFonts() throws Exception {
            Document doc = new Document(getMyDir() + "Rendering.doc");
        
            // Set the option to export font resources.
            HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.MHTML);
            options.setExportFontResources(true);
            // Create and pass the object which implements the handler methods.
            options.setFontSavingCallback(new HandleFontSaving());
        
            doc.save(getArtifactsDir() + "Document.SaveWithFontsExport.html", options);
        }
        
        /// <summary>
        /// Prints information about fonts and saves them alongside their output .html
        /// </summary>
        public static class HandleFontSaving implements IFontSavingCallback {
            public void fontSaving(FontSavingArgs args) throws Exception {
                // Print information about fonts
                System.out.println(MessageFormat.format("Font:\t{0}", args.getFontFamilyName()));
                if (args.getBold()) System.out.println(", bold");
                if (args.getItalic()) System.out.println(", italic");
                System.out.println(MessageFormat.format("\nSource:\t{0}, {1} bytes\n", args.getOriginalFileName(), args.getOriginalFileSize()));
        
                Assert.assertTrue(args.isExportNeeded());
                Assert.assertTrue(args.isSubsettingNeeded());
        
                // We can designate where each font will be saved by either specifying a file name, or creating a new stream
                String[] parts = args.getOriginalFileName().split(File.separator + File.separator);
                String lastOne = parts[parts.length - 1];
                args.setFontFileName(lastOne);
        
                Assert.assertFalse(args.getKeepFontStreamOpen());
                // We can access the source document from here also
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
            }
        }
      • getFontsFolder/setFontsFolder

        public java.lang.String getFontsFolder() / public void setFontsFolder(java.lang.String value)
        
        Specifies the physical folder where fonts are saved when exporting a document to HTML. Default is an empty string.

        When you save a Document in HTML format and ExportFontResources is set to true, Aspose.Words needs to save fonts used in the document as standalone files. FontsFolder allows you to specify where the fonts will be saved and FontsFolderAlias allows to specify how the font URIs will be constructed.

        If you save a document into a file and provide a file name, Aspose.Words, by default, saves the fonts in the same folder where the document file is saved. Use FontsFolder to override this behavior.

        If you save a document into a stream, Aspose.Words does not have a folder where to save the fonts, but still needs to save the fonts somewhere. In this case, you need to specify an accessible folder in the FontsFolder property or provide custom streams via the FontSavingCallback event handler.

        If the folder specified by FontsFolder doesn't exist, it will be created automatically.

        ResourceFolder is another way to specify a folder where fonts should be saved.

        Example:

        Shows how to set folders and folder aliases for externally saved resources when saving to html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setImageResolution(72);
            options.setFontResourcesSubsettingSizeThreshold(0);
            options.setFontsFolder(getArtifactsDir() + "Fonts");
            options.setImagesFolder(getArtifactsDir() + "Images");
            options.setResourceFolder(getArtifactsDir() + "Resources");
            options.setFontsFolderAlias("http://example.com/fonts");
            options.setImagesFolderAlias("http://example.com/images");
            options.setResourceFolderAlias("http://example.com/resources");
            options.setExportOriginalUrlForLinkedImages(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FolderAlias.html", options);
        See Also:
        ResourceFolder, ExportFontResources, FontsFolderAlias, FontSavingCallback
      • getFontsFolderAlias/setFontsFolderAlias

        public java.lang.String getFontsFolderAlias() / public void setFontsFolderAlias(java.lang.String value)
        
        Specifies the name of the folder used to construct font URIs written into an HTML document. Default is an empty string.

        When you save a Document in HTML format and ExportFontResources is set to true, Aspose.Words needs to save fonts used in the document as standalone files. FontsFolder allows you to specify where the fonts will be saved and FontsFolderAlias allows to specify how the font URIs will be constructed.

        If FontsFolderAlias is not an empty string, then the font URI written to HTML will be FontsFolderAlias + <font file name>.

        If FontsFolderAlias is an empty string, then the font URI written to HTML will be FontsFolder + <font file name>.

        If FontsFolderAlias is set to '.' (dot), then the font file name will be written to HTML without path regardless of other options.

        Alternative way to specify the name of the folder to construct font URIs is to use ResourceFolderAlias.

        Example:

        Shows how to set folders and folder aliases for externally saved resources when saving to html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setImageResolution(72);
            options.setFontResourcesSubsettingSizeThreshold(0);
            options.setFontsFolder(getArtifactsDir() + "Fonts");
            options.setImagesFolder(getArtifactsDir() + "Images");
            options.setResourceFolder(getArtifactsDir() + "Resources");
            options.setFontsFolderAlias("http://example.com/fonts");
            options.setImagesFolderAlias("http://example.com/images");
            options.setResourceFolderAlias("http://example.com/resources");
            options.setExportOriginalUrlForLinkedImages(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FolderAlias.html", options);
        See Also:
        ResourceFolderAlias, ExportFontResources, FontsFolder, FontSavingCallback
      • getHtmlVersion/setHtmlVersion

        public int getHtmlVersion() / public void setHtmlVersion(int value)
        
        Specifies version of HTML standard that should be used when saving the document to HTML or MHTML. Default value is HtmlVersion.XHTML. The value of the property is HtmlVersion integer constant.

        Example:

        Shows how to set a saved .html document to a specific version.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // Save the document to a .html file of the XHTML 1.0 Transitional standard
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
        {
            options.setHtmlVersion(com.aspose.words.HtmlVersion.XHTML);
            options.setExportXhtmlTransitional(true);
            options.setPrettyFormat(true);
        }
        
        // The DOCTYPE declaration at the top of this document will indicate the html version we chose
        doc.save(getArtifactsDir() + "HtmlSaveOptions.HtmlVersion.html", options);
      • getImageResolution/setImageResolution

        public int getImageResolution() / public void setImageResolution(int value)
        
        Specifies the output resolution for images when exporting to HTML, MHTML or EPUB. Default is 96 dpi.

        This property effects raster images when ScaleImageToShapeSize is true and effects metafiles exported as raster images. Some image properties such as cropping or rotation require saving transformed images and in this case transformed images are created in the given resolution.

        Example:

        Shows how to set folders and folder aliases for externally saved resources when saving to html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setImageResolution(72);
            options.setFontResourcesSubsettingSizeThreshold(0);
            options.setFontsFolder(getArtifactsDir() + "Fonts");
            options.setImagesFolder(getArtifactsDir() + "Images");
            options.setResourceFolder(getArtifactsDir() + "Resources");
            options.setFontsFolderAlias("http://example.com/fonts");
            options.setImagesFolderAlias("http://example.com/images");
            options.setResourceFolderAlias("http://example.com/resources");
            options.setExportOriginalUrlForLinkedImages(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FolderAlias.html", options);
        See Also:
        ScaleImageToShapeSize
      • getImageSavingCallback/setImageSavingCallback

        public IImageSavingCallback getImageSavingCallback() / public void setImageSavingCallback(IImageSavingCallback value)
        
        Allows to control how images are saved when a document is saved to HTML, MHTML or EPUB.

        Example:

        Shows how to define custom logic for controlling how images are saved when exporting to HTML based formats.
        public void saveHtmlExportImages() throws Exception {
            Document doc = new Document(getMyDir() + "Document.doc");
        
            // Create and pass the object which implements the handler methods.
            HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
            options.setImageSavingCallback(new HandleImageSaving());
        
            doc.save(getArtifactsDir() + "Document.SaveWithCustomImagesExport.html", options);
        }
        
        public class HandleImageSaving implements IImageSavingCallback {
            public void imageSaving(final ImageSavingArgs args) throws Exception {
                // Change any images in the document being exported with the extension of "jpeg" to "jpg".
                if (args.getImageFileName().endsWith(".jpeg"))
                    args.setImageFileName(args.getImageFileName().replace(".jpeg", ".jpg"));
            }
        }

        Example:

        Shows how split a document into parts and save them.
        public void documentParts() throws Exception {
            // Open a document to be converted to html
            Document doc = new Document(getMyDir() + "Rendering.doc");
            String outFileName = "SavingCallback.DocumentParts.Rendering.html";
        
            // We can use an appropriate SaveOptions subclass to customize the conversion process
            HtmlSaveOptions options = new HtmlSaveOptions();
        
            // We can use it to split a document into smaller parts, in this instance split by section breaks
            // Each part will be saved into a separate file, creating many files during the conversion process instead of just one
            options.setDocumentSplitCriteria(DocumentSplitCriteria.SECTION_BREAK);
        
            // We can set a callback to name each document part file ourselves
            options.setDocumentPartSavingCallback(new SavedDocumentPartRename(outFileName, options.getDocumentSplitCriteria()));
        
            // If we convert a document that contains images into html, we will end up with one html file which links to several images
            // Each image will be in the form of a file in the local file system
            // There is also a callback that can customize the name and file system location of each image
            options.setImageSavingCallback(new SavedImageRename(outFileName));
        
            // The DocumentPartSaving() and ImageSaving() methods of our callbacks will be run at this time
            doc.save(getArtifactsDir() + outFileName, options);
        }
        
        /// <summary>
        /// Renames saved document parts that are produced when an HTML document is saved while being split according to a criteria
        /// </summary>
        private static class SavedDocumentPartRename implements IDocumentPartSavingCallback {
            public SavedDocumentPartRename(String outFileName, int documentSplitCriteria) {
                mOutFileName = outFileName;
                mDocumentSplitCriteria = documentSplitCriteria;
            }
        
            public void documentPartSaving(DocumentPartSavingArgs args) throws Exception {
                Assert.assertTrue(args.getDocument().getOriginalFileName().endsWith("Rendering.doc"));
        
                String partType = "";
        
                switch (mDocumentSplitCriteria) {
                    case DocumentSplitCriteria.PAGE_BREAK:
                        partType = "Page";
                        break;
                    case DocumentSplitCriteria.COLUMN_BREAK:
                        partType = "Column";
                        break;
                    case DocumentSplitCriteria.SECTION_BREAK:
                        partType = "Section";
                        break;
                    case DocumentSplitCriteria.HEADING_PARAGRAPH:
                        partType = "Paragraph from heading";
                        break;
                }
        
                String partFileName = MessageFormat.format("{0} part {1}, of type {2}.{3}", mOutFileName, ++mCount, partType, FilenameUtils.getExtension(args.getDocumentPartFileName()));
        
                // We can designate the filename and location of each output file either by filename
                args.setDocumentPartFileName(partFileName);
        
                // Or we can make a new stream and choose the location of the file at construction
                try {
                    FileOutputStream outputStream = new FileOutputStream(getArtifactsDir() + partFileName);
                    args.setDocumentPartStream(outputStream);
                } catch (IOException e) {
                    e.printStackTrace();
                }
        
                Assert.assertNotNull(args.getDocumentPartStream());
                Assert.assertFalse(args.getKeepDocumentPartStreamOpen());
            }
        
            private int mCount;
            private String mOutFileName;
            private int mDocumentSplitCriteria;
        }
        
        /// <summary>
        /// Renames saved images that are produced when an HTML document is saved
        /// </summary>
        public static class SavedImageRename implements IImageSavingCallback {
            public SavedImageRename(String outFileName) {
                mOutFileName = outFileName;
            }
        
            public void imageSaving(ImageSavingArgs args) throws Exception {
                // Same filename and stream functions as above in IDocumentPartSavingCallback apply here
                String imageFileName = MessageFormat.format("{0} shape {1}, of type {2}.{3}", mOutFileName, ++mCount, args.getCurrentShape().getShapeType(), FilenameUtils.getExtension(args.getImageFileName()));
        
                args.setImageFileName(imageFileName);
        
                try {
                    FileOutputStream outputStream = new FileOutputStream(getArtifactsDir() + imageFileName);
                    args.setImageStream(outputStream);
                } catch (IOException e) {
                    e.printStackTrace();
                }
        
                Assert.assertNotNull(args.getImageStream());
                Assert.assertTrue(args.isImageAvailable());
                Assert.assertFalse(args.getKeepImageStreamOpen());
            }
        
            private int mCount;
            private String mOutFileName;
        }
      • getImagesFolder/setImagesFolder

        public java.lang.String getImagesFolder() / public void setImagesFolder(java.lang.String value)
        
        Specifies the physical folder where images are saved when exporting a document to HTML format. Default is an empty string.

        When you save a Document in HTML format, Aspose.Words needs to save all images embedded in the document as standalone files. ImagesFolder allows you to specify where the images will be saved and ImagesFolderAlias allows to specify how the image URIs will be constructed.

        If you save a document into a file and provide a file name, Aspose.Words, by default, saves the images in the same folder where the document file is saved. Use ImagesFolder to override this behavior.

        If you save a document into a stream, Aspose.Words does not have a folder where to save the images, but still needs to save the images somewhere. In this case, you need to specify an accessible folder in the ImagesFolder property or provide custom streams via the ImageSavingCallback event handler.

        If the folder specified by ImagesFolder doesn't exist, it will be created automatically.

        ResourceFolder is another way to specify a folder where images should be saved.

        Example:

        Shows how to set save options before saving a document to HTML.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // This is the directory we want the exported images to be saved to.
        File imagesDir = new File(getMyDir(), "SaveHtmlWithOptions");
        
        // The folder specified needs to exist and should be empty.
        if (imagesDir.exists()) {
            imagesDir.delete();
        }
        
        imagesDir.mkdir();
        
        // Set an option to export form fields as plain text, not as HTML input elements.
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
        options.setExportTextInputFormFieldAsText(true);
        options.setImagesFolder(imagesDir.getPath());
        
        doc.save(getArtifactsDir() + "Document.SaveWithOptions.html", options);
        See Also:
        ResourceFolder, ImagesFolderAlias, ImageSavingCallback
      • getImagesFolderAlias/setImagesFolderAlias

        public java.lang.String getImagesFolderAlias() / public void setImagesFolderAlias(java.lang.String value)
        
        Specifies the name of the folder used to construct image URIs written into an HTML document. Default is an empty string.

        When you save a Document in HTML format, Aspose.Words needs to save all images embedded in the document as standalone files. ImagesFolder allows you to specify where the images will be saved and ImagesFolderAlias allows to specify how the image URIs will be constructed.

        If ImagesFolderAlias is not an empty string, then the image URI written to HTML will be ImagesFolderAlias + <image file name>.

        If ImagesFolderAlias is an empty string, then the image URI written to HTML will be ImagesFolder + <image file name>.

        If ImagesFolderAlias is set to '.' (dot), then the image file name will be written to HTML without path regardless of other options.

        Alternative way to specify the name of the folder to construct image URIs is to use ResourceFolderAlias.

        Example:

        Shows how to set folders and folder aliases for externally saved resources when saving to html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setImageResolution(72);
            options.setFontResourcesSubsettingSizeThreshold(0);
            options.setFontsFolder(getArtifactsDir() + "Fonts");
            options.setImagesFolder(getArtifactsDir() + "Images");
            options.setResourceFolder(getArtifactsDir() + "Resources");
            options.setFontsFolderAlias("http://example.com/fonts");
            options.setImagesFolderAlias("http://example.com/images");
            options.setResourceFolderAlias("http://example.com/resources");
            options.setExportOriginalUrlForLinkedImages(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FolderAlias.html", options);
        See Also:
        ResourceFolderAlias, ImagesFolder, ImageSavingCallback
      • getMemoryOptimization/setMemoryOptimization

        public boolean getMemoryOptimization() / public void setMemoryOptimization(boolean value)
        
        Gets or sets value determining if memory optimization should be performed before saving the document. Default value for this property is false. Setting this option to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time.

        Example:

        Shows an option to optimize memory consumption when you work with large documents.
        Document doc = new Document(getMyDir() + "SaveOptions.MemoryOptimization.doc");
        
        // When set to true it will improve document memory footprint but will add extra time to processing. 
        // This optimization is only applied during save operation.
        SaveOptions saveOptions = SaveOptions.createSaveOptions(SaveFormat.PDF);
        saveOptions.setMemoryOptimization(true);
        
        doc.save(getArtifactsDir() + "SaveOptions.MemoryOptimization.pdf", saveOptions);
      • getMetafileFormat/setMetafileFormat

        public int getMetafileFormat() / public void setMetafileFormat(int value)
        
        Specifies in what format metafiles are saved when exporting to HTML, MHTML, or EPUB. Default value is HtmlMetafileFormat.PNG, meaning that metafiles are rendered to raster PNG images. The value of the property is HtmlMetafileFormat integer constant.

        Metafiles are not natively displayed by HTML browsers. By default, Aspose.Words converts WMF and EMF images into PNG files when exporting to HTML. Other options are to convert metafiles to SVG images or to export them as is without conversion.

        Some image transforms, in particular image cropping, will not be applied to metafile images if they are exported to HTML without conversion.

        Example:

        Shows how to set a meta file in a different format.
        // Create a document from an html string
        String html =
                "<html>\r\n<svg xmlns='http://www.w3.org/2000/svg' width='500' height='40' viewBox='0 0 500 40'>\r\n<text x='0' y='35' font-family='Verdana' font-size='35'>Hello world!</text>\r\n</svg>\r\n</html>";
        
        Document doc = new Document(new ByteArrayInputStream(html.getBytes()));
        
        // This document contains a <svg> element in the form of text,
        // which by default will be saved as a linked external .png when we save the document as html
        // We can save with a HtmlSaveOptions object with this flag set to preserve the <svg> tag
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setMetafileFormat(HtmlMetafileFormat.SVG);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.MetafileFormat.html", options);
        See Also:
        ImageResolution, ScaleImageToShapeSize
      • getOfficeMathOutputMode/setOfficeMathOutputMode

        public int getOfficeMathOutputMode() / public void setOfficeMathOutputMode(int value)
        
        Controls how OfficeMath objects are exported to HTML, MHTML or EPUB. Default value is HtmlOfficeMathOutputMode.Image. The value of the property is HtmlOfficeMathOutputMode integer constant.

        Example:

        Shows how to control the way how OfficeMath objects are exported to .html.
        // Open a document that contains OfficeMath objects
        Document doc = new Document(getMyDir() + "Shape.OfficeMath.docx");
        
        // Create a HtmlSaveOptions object and configure it to export OfficeMath objects as images
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setOfficeMathOutputMode(HtmlOfficeMathOutputMode.IMAGE);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.OfficeMathOutputMode.html", options);
      • getPrettyFormat/setPrettyFormat

        public boolean getPrettyFormat() / public void setPrettyFormat(boolean value)
        
        When true, pretty formats output where applicable. Default value is false.

        Set to true to make HTML, MHTML, EPUB, WordML, RTF, DOCX and ODT output human readable. Useful for testing or debugging.

        Example:

        Shows how to pass an option to export HTML tags in a well spaced, human readable format.
        Document doc = new Document(getMyDir() + "Document.doc");
        
        HtmlSaveOptions htmlOptions = new HtmlSaveOptions(SaveFormat.HTML);
        // Enabling the PrettyFormat setting will export HTML in an indented format that is easy to read.
        // If this is setting is false (by default) then the HTML tags will be exported in condensed form with no indentation.
        htmlOptions.setPrettyFormat(true);
        
        doc.save(getArtifactsDir() + "Document.PrettyFormat.html", htmlOptions);
      • getResolveFontNames/setResolveFontNames

        public boolean getResolveFontNames() / public void setResolveFontNames(boolean value)
        
        Specifies whether font family names used in the document are resolved and substituted according to Document.FontSettings when being written into HTML-based formats.

        By default, this option is set to false and font family names are written to HTML as specified in source documents. That is, Document.FontSettings are ignored and no resolution or substitution of font family names is performed.

        If this option is set to true, Aspose.Words uses Document.FontSettings to resolve each font family name specified in a source document into the name of an available font family, performing font subsitution as required.

        Example:

        Shows how to resolve all font names before writing them to HTML.
        Document document = new Document(getMyDir() + "HtmlSaveOptions.ResolveFontNames.docx");
        
        FontSettings fontSettings = new FontSettings();
        fontSettings.getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("Arial");
        fontSettings.getSubstitutionSettings().getFontConfigSubstitution().setEnabled(false);
        
        document.setFontSettings(fontSettings);
        
        HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);
        // By default this option is set to 'False' and Aspose.Words writes font names as specified in the source document.
        saveOptions.setResolveFontNames(true);
        
        document.save(getArtifactsDir() + "HtmlSaveOptions.ResolveFontNames.html", saveOptions);
      • getResourceFolder/setResourceFolder

        public java.lang.String getResourceFolder() / public void setResourceFolder(java.lang.String value)
        
        Specifies a physical folder where all resources like images, fonts, and external CSS are saved when a document is exported to HTML. Default is an empty string.

        ResourceFolder is the simplest way to specify a folder where all resources should be written. Another way is to use individual properties FontsFolder, ImagesFolder, and CssStyleSheetFileName.

        ResourceFolder has a lower priority than folders specified via FontsFolder, ImagesFolder, and CssStyleSheetFileName. For example, if both ResourceFolder and FontsFolder are specified, fonts will be saved to FontsFolder, while images and CSS will be saved to ResourceFolder.

        If the folder specified by ResourceFolder doesn't exist, it will be created automatically.

        Example:

        Shows how to set folders and folder aliases for externally saved resources when saving to html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setImageResolution(72);
            options.setFontResourcesSubsettingSizeThreshold(0);
            options.setFontsFolder(getArtifactsDir() + "Fonts");
            options.setImagesFolder(getArtifactsDir() + "Images");
            options.setResourceFolder(getArtifactsDir() + "Resources");
            options.setFontsFolderAlias("http://example.com/fonts");
            options.setImagesFolderAlias("http://example.com/images");
            options.setResourceFolderAlias("http://example.com/resources");
            options.setExportOriginalUrlForLinkedImages(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FolderAlias.html", options);
        See Also:
        FontsFolder, ImagesFolder, CssStyleSheetFileName
      • getResourceFolderAlias/setResourceFolderAlias

        public java.lang.String getResourceFolderAlias() / public void setResourceFolderAlias(java.lang.String value)
        
        Specifies the name of the folder used to construct URIs of all resources written into an HTML document. Default is an empty string.

        ResourceFolderAlias is the simplest way to specify how URIs for all resource files should be constructed. Same information can be specified for images and fonts separately via ImagesFolderAlias and FontsFolderAlias properties, respectively. However, there is no individual property for CSS.

        ResourceFolderAlias has lower priority than FontsFolderAlias and ImagesFolderAlias. For example, if both ResourceFolderAlias and FontsFolderAlias are specified, fonts' URIs will be constructed using FontsFolderAlias, while URIs of images and CSS will be constructed using ResourceFolderAlias.

        If ResourceFolderAlias is empty, the ResourceFolder property value will be used to construct resource URIs.

        If ResourceFolderAlias is set to '.' (dot), resource URIs will contain file names only, without any path.

        Example:

        Shows how to set folders and folder aliases for externally saved resources when saving to html.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        HtmlSaveOptions options = new HtmlSaveOptions();
        {
            options.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
            options.setExportFontResources(true);
            options.setImageResolution(72);
            options.setFontResourcesSubsettingSizeThreshold(0);
            options.setFontsFolder(getArtifactsDir() + "Fonts");
            options.setImagesFolder(getArtifactsDir() + "Images");
            options.setResourceFolder(getArtifactsDir() + "Resources");
            options.setFontsFolderAlias("http://example.com/fonts");
            options.setImagesFolderAlias("http://example.com/images");
            options.setResourceFolderAlias("http://example.com/resources");
            options.setExportOriginalUrlForLinkedImages(true);
        }
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.FolderAlias.html", options);
        See Also:
        ResourceFolder, FontsFolderAlias, ImagesFolderAlias
      • getSaveFormat/setSaveFormat

        public int getSaveFormat() / public void setSaveFormat(int value)
        
        Specifies the format in which the document will be saved if this save options object is used. Can be SaveFormat.HTML, SaveFormat.MHTML or SaveFormat.EPUB. The value of the property is SaveFormat integer constant.

        Example:

        Converts a document to EPUB with save options specified.
        // Open an existing document from disk.
        Document doc = new Document(getMyDir() + "Document.EpubConversion.doc");
        
        // Create a new instance of HtmlSaveOptions. This object allows us to set options that control
        // how the output document is saved.
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        
        // Specify the desired encoding.
        saveOptions.setEncoding(Charset.forName("UTF-8"));
        
        // Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
        // which allows you to limit the size of each HTML part. This is useful for readers which cannot read
        // HTML files greater than a certain size e.g 300kb.
        saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
        
        // Specify that we want to export document properties.
        saveOptions.setExportDocumentProperties(true);
        
        // Specify that we want to save in EPUB format.
        saveOptions.setSaveFormat(SaveFormat.EPUB);
        
        // Export the document as an EPUB file.
        doc.save(getArtifactsDir() + "Document.EpubConversion.epub", saveOptions);
      • getScaleImageToShapeSize/setScaleImageToShapeSize

        public boolean getScaleImageToShapeSize() / public void setScaleImageToShapeSize(boolean value)
        
        Specifies whether images are scaled by Aspose.Words to the bounding shape size when exporting to HTML, MHTML or EPUB. Default value is true.

        An image in a Microsoft Word document is a shape. The shape has a size and the image has its own size. The sizes are not directly linked. For example, the image can be 1024x786 pixels, but shape that displays this image can be 400x300 points.

        In order to display an image in the browser, it must be scaled to the shape size. The ScaleImageToShapeSize property controls where the scaling of the image takes place: in Aspose.Words during export to HTML or in the browser when displaying the document.

        When ScaleImageToShapeSize is true, the image is scaled by Aspose.Words using high quality scaling during export to HTML. When ScaleImageToShapeSize is false, the image is output with its original size and the browser has to scale it.

        In general, browsers do quick and poor quality scaling. As a result, you will normally get better display quality in the browser and smaller file size when ScaleImageToShapeSize is true, but better printing quality and faster conversion when ScaleImageToShapeSize is false.

        Example:

        Shows how to disable the scaling of images to their parent shape dimensions when saving to .html.
        // Open a document which contains shapes with images
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // By default, images inside shapes get scaled to the size of their shapes while the document gets
        // converted to .html, reducing image file size
        // We can save the document with a HtmlSaveOptions with ScaleImageToShapeSize set to false to prevent the scaling
        // and preserve the full quality and file size of the linked images
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setScaleImageToShapeSize(false);
        
        doc.save(getArtifactsDir() + "HtmlSaveOptions.ScaleImageToShapeSize.html", options);
        See Also:
        ImageResolution
      • getTableWidthOutputMode/setTableWidthOutputMode

        public int getTableWidthOutputMode() / public void setTableWidthOutputMode(int value)
        
        Controls how table, row and cell widths are exported to HTML, MHTML or EPUB. Default value is HtmlElementSizeOutputMode.ALL. The value of the property is HtmlElementSizeOutputMode integer constant.

        In the HTML format, table, row and cell elements (<table>, <tr>, <th>, <td>) can have their widths specified either in relative (percentage) or in absolute units. In a document in Aspose.Words, tables, rows and cells can have their widths specified using either relative or absolute units too.

        When you convert a document to HTML using Aspose.Words, you might want to control how table, row and cell widths are exported to affect how the resulting document is displayed in the visual agent (e.g. a browser or viewer).

        Use this property as a filter to specify what table widths values are exported into the destination document. For example, if you are converting a document to EPUB and intend to view the document on a mobile reading device, then you probably want to avoid exporting absolute width values. To do this you need to specify the output mode HtmlElementSizeOutputMode.RELATIVE_ONLY or HtmlElementSizeOutputMode.NONE so the viewer on the mobile device can layout the table to fit the width of the screen as best as it can.

        Example:

        Shows how to preserve negative indents in the output .html.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a table and give it a negative value for its indent, effectively pushing it out of the left page boundary
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1");
        builder.insertCell();
        builder.write("Cell 2");
        builder.endTable();
        table.setLeftIndent(-36);
        table.setPreferredWidth(PreferredWidth.fromPoints(144.0));
        
        // When saving to .html, this indent will only be preserved if we set this flag
        HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
        options.setAllowNegativeIndent(true);
        options.setTableWidthOutputMode(HtmlElementSizeOutputMode.RELATIVE_ONLY);
        
        // The first cell with "Cell 1" will not be visible in the output
        doc.save(getArtifactsDir() + "HtmlSaveOptions.AllowNegativeIndent.html", options);
      • getTempFolder/setTempFolder

        public java.lang.String getTempFolder() / public void setTempFolder(java.lang.String value)
        
        Specifies the folder for temporary files used when saving to a DOC or DOCX file. By default this property is null and no temporary files are used.

        When Aspose.Words saves a document, it needs to create temporary internal structures. By default, these internal structures are created in memory and the memory usage spikes for a short period while the document is being saved. When saving is complete, the memory is freed and reclaimed by the garbage collector.

        If you are saving a very large document (thousands of pages) and/or processing many documents at the same time, then the memory spike during saving can be significant enough to cause the system to throw System.OutOfMemoryException. Specifying a temporary folder using TempFolder will cause Aspose.Words to keep the internal structures in temporary files instead of memory. It reduces the memory usage during saving, but will decrease the save performance.

        The folder must exist and be writable, otherwise an exception will be thrown.

        Aspose.Words automatically deletes all temporary files when saving is complete.

        Example:

        Shows how to save a document using temporary files.
        Document doc = new Document(getMyDir() + "Rendering.doc");
        
        // We can use a SaveOptions object to set the saving method of a document from a MemoryStream to temporary files
        // While saving, the files will briefly pop up in the folder we set as the TempFolder attribute below
        // Doing this will free up space in the memory that the stream would usually occupy
        DocSaveOptions options = new DocSaveOptions();
        options.setTempFolder(getArtifactsDir() + "TempFiles");
        
        // Ensure that the directory exists and save
        new File(options.getTempFolder()).mkdir();
        
        doc.save(getArtifactsDir() + "DocSaveOptions.TempFolder.doc", options);
      • getUpdateFields/setUpdateFields

        public boolean getUpdateFields() / public void setUpdateFields(boolean value)
        
        Gets or sets a value determining if fields of certain types should be updated before saving the document to a fixed page format. Default value for this property is true. Allows to specify whether to mimic or not MS Word behaviour.

        Example:

        Shows how to update fields before saving into a PDF document.
        Document doc = DocumentHelper.createDocumentFillWithDummyText();
        
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.setUpdateFields(false);
        
        // PdfSaveOptions objects can be cloned
        Assert.assertNotSame(pdfSaveOptions, pdfSaveOptions.deepClone());
        
        doc.save(getArtifactsDir() + "UpdateFields_False.pdf", pdfSaveOptions);
      • getUpdateLastSavedTimeProperty/setUpdateLastSavedTimeProperty

        public boolean getUpdateLastSavedTimeProperty() / public void setUpdateLastSavedTimeProperty(boolean value)
        
        Gets or sets a value determining whether the BuiltInDocumentProperties.LastSavedTime property is updated before saving.

        Example:

        Shows how to update a document time property when you want to save it
        Document doc = new Document(getMyDir() + "Document.doc");
        
        //Get last saved time
        Date documentTimeBeforeSave = doc.getBuiltInDocumentProperties().getLastSavedTime();
        
        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
        saveOptions.setUpdateLastSavedTimeProperty(true);
        
        doc.save(getArtifactsDir() + "OoxmlSaveOptions.UpdatingLastSavedTimeDocument.docx", saveOptions);
      • getUpdateSdtContent/setUpdateSdtContent

        public boolean getUpdateSdtContent() / public void setUpdateSdtContent(boolean value)
        
        Gets or sets value determining whether content of StructuredDocumentTag is updated before saving. The default value is true.

        Example:

        Shows how structured document tags can be updated while saving to .pdf.
        Document doc = new Document();
        
        // Insert two StructuredDocumentTags; a date and a drop down list
        StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.DATE, MarkupLevel.BLOCK);
        tag.setFullDate(new Date());
        
        doc.getFirstSection().getBody().appendChild(tag);
        
        tag = new StructuredDocumentTag(doc, SdtType.DROP_DOWN_LIST, MarkupLevel.BLOCK);
        tag.getListItems().add(new SdtListItem("Value 1"));
        tag.getListItems().add(new SdtListItem("Value 2"));
        tag.getListItems().add(new SdtListItem("Value 3"));
        tag.getListItems().setSelectedValue(tag.getListItems().get(1));
        
        doc.getFirstSection().getBody().appendChild(tag);
        
        // We've selected default values for both tags
        // We can save those values in the document without immediately updating the tags, leaving them in their default state
        // by using a SaveOptions object with this flag set
        PdfSaveOptions options = new PdfSaveOptions();
        options.setUpdateSdtContent(false);
        
        doc.save(getArtifactsDir() + "UpdateSdtContent.pdf", options);
      • getUseAntiAliasing/setUseAntiAliasing

        public boolean getUseAntiAliasing() / public void setUseAntiAliasing(boolean value)
        
        Gets or sets a value determining whether or not to use anti-aliasing for rendering.

        The default value is false. When this value is set to true anti-aliasing is used for rendering.

        This property is used when the document is exported to the following formats: SaveFormat.TIFF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.JPEG, SaveFormat.EMF. When the document is exported to the SaveFormat.HTML, SaveFormat.MHTML and SaveFormat.EPUB formats this option is used for raster images.

        Example:

        Improve the quality of a rendered document with SaveOptions.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setSize(60.0);
        
        builder.writeln("Some text.");
        
        SaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
        Assert.assertEquals(options.getUseAntiAliasing(), false);
        
        doc.save(getArtifactsDir() + "Document.SaveOptionsDefault.jpg", options);
        
        options.setUseAntiAliasing(true);
        options.setUseHighQualityRendering(true);
        doc.save(getArtifactsDir() + "Document.SaveOptionsHighQuality.jpg", options);
      • getUseHighQualityRendering/setUseHighQualityRendering

        public boolean getUseHighQualityRendering() / public void setUseHighQualityRendering(boolean value)
        
        Gets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms. The default value is false.

        This property is used when the document is exported to image formats: SaveFormat.TIFF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.JPEG, SaveFormat.EMF.

        Example:

        Improve the quality of a rendered document with SaveOptions.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setSize(60.0);
        
        builder.writeln("Some text.");
        
        SaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
        Assert.assertEquals(options.getUseAntiAliasing(), false);
        
        doc.save(getArtifactsDir() + "Document.SaveOptionsDefault.jpg", options);
        
        options.setUseAntiAliasing(true);
        options.setUseHighQualityRendering(true);
        doc.save(getArtifactsDir() + "Document.SaveOptionsHighQuality.jpg", options);