com.aspose.words

Class HtmlLoadOptions

  • java.lang.Object
public class HtmlLoadOptions 
extends LoadOptions

Allows to specify additional options when loading HTML document into a Document object.

Constructor Summary
HtmlLoadOptions()
Initializes a new instance of this class with default values.
HtmlLoadOptions(java.lang.Stringpassword)
A shortcut to initialize a new instance of this class with the specified password to load an encrypted document.
HtmlLoadOptions(intloadFormat, java.lang.Stringpassword, java.lang.StringbaseUri)
A shortcut to initialize a new instance of this class with properties set to the specified values.
 
Property Getters/Setters Summary
java.lang.StringgetBaseUri()
void
setBaseUri(java.lang.Stringvalue)
           Gets or sets the string that will be used to resolve relative URIs found in the document into absolute URIs when required. Can be null or empty string. Default is null.
booleangetConvertMetafilesToPng()
void
           Gets or sets whether to convert metafile (Wmf or Emf ) images to Png image format.
booleangetConvertShapeToOfficeMath()
void
           Gets or sets whether to convert shapes with EquationXML to Office Math objects.
booleangetConvertSvgToEmf()
void
setConvertSvgToEmf(booleanvalue)
           Gets or sets a value indicating whether to convert loaded SVG images to the EMF format. Default value is false and, if possible, loaded SVG images are stored as is without conversion.
java.nio.charset.CharsetgetEncoding()
void
setEncoding(java.nio.charset.Charsetvalue)
           Gets or sets the encoding that will be used to load an HTML, TXT, or CHM document if the encoding is not specified inside the document. Can be null. Default is null.
booleangetFlatOpcXmlMappingOnly()
void
           Gets or sets value determining which document formats are allowed to be mapped by StructuredDocumentTag.XmlMapping. By default only LoadFormat.FLAT_OPC document format is allowed to be mapped.
FontSettingsgetFontSettings()
void
           Allows to specify document font settings.
booleangetIgnoreNoscriptElements()
void
           Gets or sets a value indicating whether to ignore <noscript> HTML elements. Default value is false.
LanguagePreferencesgetLanguagePreferences()
Gets language preferences that will be used when document is loading.
intgetLoadFormat()
void
setLoadFormat(intvalue)
           Specifies the format of the document to be loaded. Default is LoadFormat.AUTO. The value of the property is LoadFormat integer constant.
intgetMswVersion()
void
setMswVersion(intvalue)
           Allows to specify that the document loading process should match a specific MS Word version. Default value is MsWordVersion.WORD_2019The value of the property is MsWordVersion integer constant.
java.lang.StringgetPassword()
void
setPassword(java.lang.Stringvalue)
           Gets or sets the password for opening an encrypted document. Can be null or empty string. Default is null.
intgetPreferredControlType()
void
           Gets or sets preferred type of document nodes that will represent imported <input> and <select> elements. Default value is HtmlControlType.FORM_FIELD. The value of the property is HtmlControlType integer constant.
booleangetPreserveIncludePictureField()
void
           Gets or sets whether to preserve the INCLUDEPICTURE field when reading Microsoft Word formats. The default value is false.
IDocumentLoadingCallbackgetProgressCallback()
void
           Called during loading a document and accepts data about loading progress.
IResourceLoadingCallbackgetResourceLoadingCallback()
void
           Allows to control how external resources (images, style sheets) are loaded when a document is imported from HTML, MHTML.
booleangetSupportVml()
void
setSupportVml(booleanvalue)
           Gets or sets a value indicating whether to support VML images.
java.lang.StringgetTempFolder()
void
setTempFolder(java.lang.Stringvalue)
           Allows to use temporary files when reading document. By default this property is null and no temporary files are used.
booleangetUpdateDirtyFields()
void
setUpdateDirtyFields(booleanvalue)
           Specifies whether to update the fields with the dirty attribute.
IWarningCallbackgetWarningCallback()
void
           Called during a load operation, when an issue is detected that might result in data or formatting fidelity loss.
intgetWebRequestTimeout()
void
           The number of milliseconds to wait before the web request times out. The default value is 100000 milliseconds (100 seconds).
 

    • Constructor Detail

      • HtmlLoadOptions

        public HtmlLoadOptions()
        Initializes a new instance of this class with default values.

        Example:

        Shows how to support conditional comments while loading an HTML document.
        HtmlLoadOptions loadOptions = new HtmlLoadOptions();
        
        // If the value is true, then we take VML code into account while parsing the loaded document.
        loadOptions.setSupportVml(supportVml);
        
        // This document contains a JPEG image within "<!--[if gte vml 1]>" tags,
        // and a different PNG image within "<![if !vml]>" tags.
        // If we set the "SupportVml" flag to "true", then Aspose.Words will load the JPEG.
        // If we set this flag to "false", then Aspose.Words will only load the PNG.
        Document doc = new Document(getMyDir() + "VML conditional.htm", loadOptions);
        
        if (supportVml)
            Assert.assertEquals(ImageType.JPEG, ((Shape) doc.getChild(NodeType.SHAPE, 0, true)).getImageData().getImageType());
        else
            Assert.assertEquals(ImageType.PNG, ((Shape) doc.getChild(NodeType.SHAPE, 0, true)).getImageData().getImageType());
      • HtmlLoadOptions

        public HtmlLoadOptions(java.lang.String password)
        A shortcut to initialize a new instance of this class with the specified password to load an encrypted document.
        Parameters:
        password - The password to open an encrypted document. Can be null or empty string.

        Example:

        Shows how to encrypt an Html document, and then open it using a password.
        // Create and sign an encrypted HTML document from an encrypted .docx.
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        SignOptions signOptions = new SignOptions();
        {
            signOptions.setComments("Comment");
            signOptions.setSignTime(new Date());
            signOptions.setDecryptionPassword("docPassword");
        }
        
        String inputFileName = getMyDir() + "Encrypted.docx";
        String outputFileName = getArtifactsDir() + "HtmlLoadOptions.EncryptedHtml.html";
        DigitalSignatureUtil.sign(inputFileName, outputFileName, certificateHolder, signOptions);
        
        // To load and read this document, we will need to pass its decryption
        // password using a HtmlLoadOptions object.
        HtmlLoadOptions loadOptions = new HtmlLoadOptions("docPassword");
        Assert.assertEquals(loadOptions.getPassword(), signOptions.getDecryptionPassword());
        
        Document doc = new Document(outputFileName, loadOptions);
        Assert.assertEquals(doc.getText().trim(), "Test encrypted document.");
      • HtmlLoadOptions

        public HtmlLoadOptions(int loadFormat, java.lang.String password, java.lang.String baseUri)
        A shortcut to initialize a new instance of this class with properties set to the specified values.
        Parameters:
        loadFormat - A LoadFormat value. The format of the document to be loaded.
        password - The password to open an encrypted document. Can be null or empty string.
        baseUri - The string that will be used to resolve relative URIs to absolute. Can be null or empty string.

        Example:

        Shows how to specify a base URI when opening an html document.
        // Suppose we want to load an .html document that contains an image linked by a relative URI
        // while the image is in a different location. In that case, we will need to resolve the relative URI into an absolute one.
        // We can provide a base URI using an HtmlLoadOptions object. 
        HtmlLoadOptions loadOptions = new HtmlLoadOptions(LoadFormat.HTML, "", getImageDir());
        
        Assert.assertEquals(LoadFormat.HTML, loadOptions.getLoadFormat());
        
        Document doc = new Document(getMyDir() + "Missing image.html", loadOptions);
        
        // While the image was broken in the input .html, our custom base URI helped us repair the link.
        Shape imageShape = (Shape) doc.getChildNodes(NodeType.SHAPE, true).get(0);
        Assert.assertTrue(imageShape.isImage());
        
        // This output document will display the image that was missing.
        doc.save(getArtifactsDir() + "HtmlLoadOptions.BaseUri.docx");
    • Property Getters/Setters Detail

      • getBaseUri/setBaseUri

        public java.lang.String getBaseUri() / public void setBaseUri(java.lang.String value)
        
        Gets or sets the string that will be used to resolve relative URIs found in the document into absolute URIs when required. Can be null or empty string. Default is null.

        This property is used to resolve relative URIs into absolute in the following cases:

        1. When loading an HTML document from a stream and the document contains images with relative URIs and does not have a base URI specified in the BASE HTML element.
        2. When saving a document to PDF and other formats, to retrieve images linked using relative URIs so the images can be saved into the output document.

        Example:

        Shows how to open an HTML document with images from a stream using a base URI.
        InputStream stream = new FileInputStream(getMyDir() + "Document.html");
        try /*JAVA: was using*/ {
            // Pass the URI of the base folder while loading it
            // so that any images with relative URIs in the HTML document can be found.
            LoadOptions loadOptions = new LoadOptions();
            loadOptions.setBaseUri(getImageDir());
        
            Document doc = new Document(stream, loadOptions);
        
            // Verify that the first shape of the document contains a valid image.
            Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
        
            Assert.assertTrue(shape.isImage());
            Assert.assertNotNull(shape.getImageData().getImageBytes());
            Assert.assertEquals(32.0, ConvertUtil.pointToPixel(shape.getWidth()), 0.01);
            Assert.assertEquals(32.0, ConvertUtil.pointToPixel(shape.getHeight()), 0.01);
        } finally {
            if (stream != null) stream.close();
        }
      • getConvertMetafilesToPng/setConvertMetafilesToPng

        public boolean getConvertMetafilesToPng() / public void setConvertMetafilesToPng(boolean value)
        
        Gets or sets whether to convert metafile (Wmf or Emf ) images to Png image format. Metafiles (Wmf or Emf ) is an uncompressed image format and sometimes requires to much RAM to hold and process document. This option allows to convert all metafile images to Png on document loading. Please note - conversion vector graphics to raster decreases quality of the images.

        Example:

        Shows how to convert WMF/EMF to PNG during loading document.
        Document doc = new Document();
        
        Shape shape = new Shape(doc, ShapeType.IMAGE);
        shape.getImageData().setImage(getImageDir() + "Windows MetaFile.wmf");
        shape.setWidth(100.0);
        shape.setHeight(100.0);
        
        doc.getFirstSection().getBody().getFirstParagraph().appendChild(shape);
        
        doc.save(getArtifactsDir() + "Image.CreateImageDirectly.docx");
        
        shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
        
        TestUtil.verifyImageInShape(1600, 1600, ImageType.WMF, shape);
        
        LoadOptions loadOptions = new LoadOptions();
        loadOptions.setConvertMetafilesToPng(true);
        
        doc = new Document(getArtifactsDir() + "Image.CreateImageDirectly.docx", loadOptions);
        shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
      • getConvertShapeToOfficeMath/setConvertShapeToOfficeMath

        public boolean getConvertShapeToOfficeMath() / public void setConvertShapeToOfficeMath(boolean value)
        
        Gets or sets whether to convert shapes with EquationXML to Office Math objects.

        Example:

        Shows how to convert EquationXML shapes to Office Math objects.
        LoadOptions loadOptions = new LoadOptions();
        
        // Use this flag to specify whether to convert the shapes with EquationXML attributes
        // to Office Math objects and then load the document.
        loadOptions.setConvertShapeToOfficeMath(isConvertShapeToOfficeMath);
        
        Document doc = new Document(getMyDir() + "Math shapes.docx", loadOptions);
        
        if (isConvertShapeToOfficeMath) {
            Assert.assertEquals(16, doc.getChildNodes(NodeType.SHAPE, true).getCount());
            Assert.assertEquals(34, doc.getChildNodes(NodeType.OFFICE_MATH, true).getCount());
        } else {
            Assert.assertEquals(24, doc.getChildNodes(NodeType.SHAPE, true).getCount());
            Assert.assertEquals(0, doc.getChildNodes(NodeType.OFFICE_MATH, true).getCount());
        }
      • getConvertSvgToEmf/setConvertSvgToEmf

        public boolean getConvertSvgToEmf() / public void setConvertSvgToEmf(boolean value)
        
        Gets or sets a value indicating whether to convert loaded SVG images to the EMF format. Default value is false and, if possible, loaded SVG images are stored as is without conversion.

        Newer versions of MS Word support SVG images natively. If the MS Word version specified in load options supports SVG, Aspose.Words will store SVG images as is without conversion. If SVG is not supported, loaded SVG images will be converted to the EMF format.

        If, however, this option is set to true, Aspose.Words will convert loaded SVG images to EMF even if SVG images are supported by the specified version of MS Word.

      • getEncoding/setEncoding

        public java.nio.charset.Charset getEncoding() / public void setEncoding(java.nio.charset.Charset value)
        
        Gets or sets the encoding that will be used to load an HTML, TXT, or CHM document if the encoding is not specified inside the document. Can be null. Default is null.

        This property is used only when loading HTML, TXT, or CHM documents.

        If encoding is not specified inside the document and this property is null, then the system will try to automatically detect the encoding.

      • getFlatOpcXmlMappingOnly/setFlatOpcXmlMappingOnly

        public boolean getFlatOpcXmlMappingOnly() / public void setFlatOpcXmlMappingOnly(boolean value)
        
        Gets or sets value determining which document formats are allowed to be mapped by StructuredDocumentTag.XmlMapping. By default only LoadFormat.FLAT_OPC document format is allowed to be mapped. This option is paired with SaveOptions.FlatOpcXmlMappingOnly. Typically you need set both of them to false to allow arbitrary document format mapped.
      • getFontSettings/setFontSettings

        public FontSettings getFontSettings() / public void setFontSettings(FontSettings value)
        
        Allows to specify document font settings.

        When loading some formats, Aspose.Words may require to resolve the fonts. For example, when loading HTML documents Aspose.Words may resolve the fonts to perform font fallback.

        If set to null, default static font settings FontSettings.DefaultInstance will be used.

        The default value is null.

        Example:

        Shows how to apply font substitution settings while loading a document.
        // Create a FontSettings object that will substitute the "Times New Roman" font
        // with the font "Arvo" from our "MyFonts" folder.
        FontSettings fontSettings = new FontSettings();
        fontSettings.setFontsFolder(getFontsDir(), false);
        fontSettings.getSubstitutionSettings().getTableSubstitution().addSubstitutes("Times New Roman", "Arvo");
        
        // Set that FontSettings object as a property of a newly created LoadOptions object.
        LoadOptions loadOptions = new LoadOptions();
        loadOptions.setFontSettings(fontSettings);
        
        // Load the document, then render it as a PDF with the font substitution.
        Document doc = new Document(getMyDir() + "Document.docx", loadOptions);
        
        doc.save(getArtifactsDir() + "LoadOptions.FontSettings.pdf");

        Example:

        Shows how to designate font substitutes during loading.
        LoadOptions loadOptions = new LoadOptions();
        loadOptions.setFontSettings(new FontSettings());
        
        // Set a font substitution rule for a LoadOptions object.
        // If the document we are loading uses a font which we do not have,
        // this rule will substitute the unavailable font with one that does exist.
        // In this case, all uses of the "MissingFont" will convert to "Comic Sans MS".
        TableSubstitutionRule substitutionRule = loadOptions.getFontSettings().getSubstitutionSettings().getTableSubstitution();
        substitutionRule.addSubstitutes("MissingFont", "Comic Sans MS");
        
        Document doc = new Document(getMyDir() + "Missing font.html", loadOptions);
        
        // At this point such text will still be in "MissingFont".
        // Font substitution will take place when we render the document.
        Assert.assertEquals("MissingFont", doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0).getFont().getName());
        
        doc.save(getArtifactsDir() + "FontSettings.ResolveFontsBeforeLoadingDocument.pdf");
      • getIgnoreNoscriptElements/setIgnoreNoscriptElements

        public boolean getIgnoreNoscriptElements() / public void setIgnoreNoscriptElements(boolean value)
        
        Gets or sets a value indicating whether to ignore <noscript> HTML elements. Default value is false. Like MS Word, Aspose.Words does not support scripts and by default loads content of <noscript> elements into the resulting document. In most browsers, however, scripts are supported and content from <noscript> is not visible. Setting this property to true forces Aspose.Words to ignore all <noscript> elements and helps to produce documents that look closer to what is seen in browsers.

        Example:

        Shows how to ignore <noscript> HTML elements.
        final String html = "\r\n<html>\r\n<head>\r\n<title>NOSCRIPT</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<script type=\"text/javascript\">\r\nalert(\"Hello, world!\");\r\n</script>\r\n</head>\r\n<body>\r\n<noscript><p>Your browser does not support JavaScript!</p></noscript>\r\n</body>\r\n</html>";
        
        HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
        htmlLoadOptions.setIgnoreNoscriptElements(ignoreNoscriptElements);
        
        Document doc = new Document(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)), htmlLoadOptions);
        doc.save(getArtifactsDir() + "HtmlLoadOptions.IgnoreNoscriptElements.pdf");
      • getLanguagePreferences

        public LanguagePreferences getLanguagePreferences()
        
        Gets language preferences that will be used when document is loading.

        Example:

        Shows how to apply language preferences when loading a document.
        LoadOptions loadOptions = new LoadOptions();
        loadOptions.getLanguagePreferences().addEditingLanguage(EditingLanguage.JAPANESE);
        
        Document doc = new Document(getMyDir() + "No default editing language.docx", loadOptions);
        
        int localeIdFarEast = doc.getStyles().getDefaultFont().getLocaleIdFarEast();
        System.out.println(localeIdFarEast == EditingLanguage.JAPANESE
                ? "The document either has no any FarEast language set in defaults or it was set to Japanese originally."
                : "The document default FarEast language was set to another than Japanese language originally, so it is not overridden.");
      • getLoadFormat/setLoadFormat

        public int getLoadFormat() / public void setLoadFormat(int value)
        
        Specifies the format of the document to be loaded. Default is LoadFormat.AUTO. The value of the property is LoadFormat integer constant.

        It is recommended that you specify the LoadFormat.AUTO value and let Aspose.Words detect the file format automatically. If you know the format of the document you are about to load, you can specify the format explicitly and this will slightly reduce the loading time by the overhead associated with auto detecting the format. If you specify an explicit load format and it will turn out to be wrong, the auto detection will be invoked and a second attempt to load the file will be made.

        Example:

        Shows how to specify a base URI when opening an html document.
        // Suppose we want to load an .html document that contains an image linked by a relative URI
        // while the image is in a different location. In that case, we will need to resolve the relative URI into an absolute one.
        // We can provide a base URI using an HtmlLoadOptions object. 
        HtmlLoadOptions loadOptions = new HtmlLoadOptions(LoadFormat.HTML, "", getImageDir());
        
        Assert.assertEquals(LoadFormat.HTML, loadOptions.getLoadFormat());
        
        Document doc = new Document(getMyDir() + "Missing image.html", loadOptions);
        
        // While the image was broken in the input .html, our custom base URI helped us repair the link.
        Shape imageShape = (Shape) doc.getChildNodes(NodeType.SHAPE, true).get(0);
        Assert.assertTrue(imageShape.isImage());
        
        // This output document will display the image that was missing.
        doc.save(getArtifactsDir() + "HtmlLoadOptions.BaseUri.docx");
      • getMswVersion/setMswVersion

        public int getMswVersion() / public void setMswVersion(int value)
        
        Allows to specify that the document loading process should match a specific MS Word version. Default value is MsWordVersion.WORD_2019The value of the property is MsWordVersion integer constant. Different Word versions may handle certain aspects of document content and formatting slightly differently during the loading process, which may result in minor differences in Document Object Model.

        Example:

        Shows how to emulate the loading procedure of a specific Microsoft Word version during document loading.
        // By default, Aspose.Words load documents according to Microsoft Word 2019 specification.
        LoadOptions loadOptions = new LoadOptions();
        
        Assert.assertEquals(MsWordVersion.WORD_2019, loadOptions.getMswVersion());
        
        // This document is missing the default paragraph formatting style.
        // This default style will be regenerated when we load the document either with Microsoft Word or Aspose.Words.
        loadOptions.setMswVersion(MsWordVersion.WORD_2007);
        Document doc = new Document(getMyDir() + "Document.docx", loadOptions);
        
        // The style's line spacing will have this value when loaded by Microsoft Word 2007 specification.
        Assert.assertEquals(12.95d, doc.getStyles().getDefaultParagraphFormat().getLineSpacing(), 0.01d);
      • getPassword/setPassword

        public java.lang.String getPassword() / public void setPassword(java.lang.String value)
        
        Gets or sets the password for opening an encrypted document. Can be null or empty string. Default is null.

        You need to know the password to open an encrypted document. If the document is not encrypted, set this to null or empty string.

        Example:

        Shows how to sign encrypted document file.
        // Create an X.509 certificate from a PKCS#12 store, which should contain a private key.
        CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
        
        // Create a comment, date, and decryption password which will be applied with our new digital signature.
        SignOptions signOptions = new SignOptions();
        {
            signOptions.setComments("Comment");
            signOptions.setSignTime(new Date());
            signOptions.setDecryptionPassword("docPassword");
        }
        
        // Set a local system filename for the unsigned input document, and an output filename for its new digitally signed copy.
        String inputFileName = getMyDir() + "Encrypted.docx";
        String outputFileName = getArtifactsDir() + "DigitalSignatureUtil.DecryptionPassword.docx";
        
        DigitalSignatureUtil.sign(inputFileName, outputFileName, certificateHolder, signOptions);
      • getPreferredControlType/setPreferredControlType

        public int getPreferredControlType() / public void setPreferredControlType(int value)
        
        Gets or sets preferred type of document nodes that will represent imported <input> and <select> elements. Default value is HtmlControlType.FORM_FIELD. The value of the property is HtmlControlType integer constant. Please note that setting this property does not guarantee that all imported controls will be of the specified type. If an HTML control is not representable with document nodes of the preferred type, Aspose.Words will use a compatible HtmlControlType for that control.

        Example:

        Shows how to set preferred type of document nodes that will represent imported <input> and <select> elements.
        final String html = "\r\n<html>\r\n<select name='ComboBox' size='1'>\r\n"
                + "<option value='val1'>item1</option>\r\n<option value='val2'></option>\r\n</select>\r\n</html>\r\n";
        
        HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
        htmlLoadOptions.setPreferredControlType(HtmlControlType.STRUCTURED_DOCUMENT_TAG);
        
        Document doc = new Document(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)), htmlLoadOptions);
        NodeCollection nodes = doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
        
        StructuredDocumentTag tag = (StructuredDocumentTag) nodes.get(0);
      • getPreserveIncludePictureField/setPreserveIncludePictureField

        public boolean getPreserveIncludePictureField() / public void setPreserveIncludePictureField(boolean value)
        
        Gets or sets whether to preserve the INCLUDEPICTURE field when reading Microsoft Word formats. The default value is false.

        By default, the INCLUDEPICTURE field is converted into a shape object. You can override that if you need the field to be preserved, for example, if you wish to update it programmatically. Note however that this approach is not common for Aspose.Words. Use it on your own risk.

        One of the possible use cases may be using a MERGEFIELD as a child field to dynamically change the source path of the picture. In this case you need the INCLUDEPICTURE to be preserved in the model.

        Example:

        Shows how to preserve or discard INCLUDEPICTURE fields when loading a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        FieldIncludePicture includePicture = (FieldIncludePicture) builder.insertField(FieldType.FIELD_INCLUDE_PICTURE, true);
        includePicture.setSourceFullName(getImageDir() + "Transparent background logo.png");
        includePicture.update(true);
        
        try (ByteArrayOutputStream docStream = new ByteArrayOutputStream()) {
            doc.save(docStream, new OoxmlSaveOptions(SaveFormat.DOCX));
        
            // We can set a flag in a LoadOptions object to decide whether to convert all INCLUDEPICTURE fields
            // into image shapes when loading a document that contains them.
            LoadOptions loadOptions = new LoadOptions();
            {
                loadOptions.setPreserveIncludePictureField(preserveIncludePictureField);
            }
        
            doc = new Document(new ByteArrayInputStream(docStream.toByteArray()), loadOptions);
            FieldCollection fieldCollection = doc.getRange().getFields();
        
            if (preserveIncludePictureField) {
                Assert.assertTrue(IterableUtils.matchesAny(fieldCollection, f -> f.getType() == FieldType.FIELD_INCLUDE_PICTURE));
        
                doc.updateFields();
                doc.save(getArtifactsDir() + "Field.PreserveIncludePicture.docx");
            } else {
                Assert.assertFalse(IterableUtils.matchesAny(fieldCollection, f -> f.getType() == FieldType.FIELD_INCLUDE_PICTURE));
            }
        }
      • getResourceLoadingCallback/setResourceLoadingCallback

        public IResourceLoadingCallback getResourceLoadingCallback() / public void setResourceLoadingCallback(IResourceLoadingCallback value)
        
        Allows to control how external resources (images, style sheets) are loaded when a document is imported from HTML, MHTML.

        Example:

        Shows how to handle external resources when loading Html documents.
        LoadOptions loadOptions = new LoadOptions();
            loadOptions.setResourceLoadingCallback(new HtmlLinkedResourceLoadingCallback());
        
            // When we load the document, our callback will handle linked resources such as CSS stylesheets and images.
            Document doc = new Document(getMyDir() + "Images.html", loadOptions);
            doc.save(getArtifactsDir() + "LoadOptions.LoadOptionsCallback.pdf");
        }
        
        /// <summary>
        /// Prints the filenames of all external stylesheets and substitutes all images of a loaded html document.
        /// </summary>
        private static class HtmlLinkedResourceLoadingCallback implements IResourceLoadingCallback {
            public int resourceLoading(ResourceLoadingArgs args) throws IOException {
                switch (args.getResourceType()) {
                    case ResourceType.CSS_STYLE_SHEET:
                        System.out.println(MessageFormat.format("External CSS Stylesheet found upon loading: {0}", args.getOriginalUri()));
                        return ResourceLoadingAction.DEFAULT;
                    case ResourceType.IMAGE:
                        System.out.println(MessageFormat.format("External Image found upon loading: {0}", args.getOriginalUri()));
        
                        final String newImageFilename = "Logo.jpg";
                        System.out.println(MessageFormat.format("\tImage will be substituted with: {0}", newImageFilename));
        
                        byte[] imageBytes = FileUtils.readFileToByteArray(new File(getImageDir() + newImageFilename));
                        args.setData(imageBytes);
        
                        return ResourceLoadingAction.USER_PROVIDED;
                }
        
                return ResourceLoadingAction.DEFAULT;
            }
        }
      • getSupportVml/setSupportVml

        public boolean getSupportVml() / public void setSupportVml(boolean value)
        
        Gets or sets a value indicating whether to support VML images.

        Example:

        Shows how to support conditional comments while loading an HTML document.
        HtmlLoadOptions loadOptions = new HtmlLoadOptions();
        
        // If the value is true, then we take VML code into account while parsing the loaded document.
        loadOptions.setSupportVml(supportVml);
        
        // This document contains a JPEG image within "<!--[if gte vml 1]>" tags,
        // and a different PNG image within "<![if !vml]>" tags.
        // If we set the "SupportVml" flag to "true", then Aspose.Words will load the JPEG.
        // If we set this flag to "false", then Aspose.Words will only load the PNG.
        Document doc = new Document(getMyDir() + "VML conditional.htm", loadOptions);
        
        if (supportVml)
            Assert.assertEquals(ImageType.JPEG, ((Shape) doc.getChild(NodeType.SHAPE, 0, true)).getImageData().getImageType());
        else
            Assert.assertEquals(ImageType.PNG, ((Shape) doc.getChild(NodeType.SHAPE, 0, true)).getImageData().getImageType());
      • getTempFolder/setTempFolder

        public java.lang.String getTempFolder() / public void setTempFolder(java.lang.String value)
        
        Allows to use temporary files when reading document. By default this property is null and no temporary files are used.

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

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

        Example:

        Shows how to load a document using temporary files.
        // Note that such an approach can reduce memory usage but degrades speed.
        LoadOptions loadOptions = new LoadOptions();
        loadOptions.setTempFolder("C:\\TempFolder\\");
        
        // Ensure that the directory exists and load.
        new File(loadOptions.getTempFolder()).mkdir();
        
        Document doc = new Document(getMyDir() + "Document.docx", loadOptions);

        Example:

        Shows how to use the hard drive instead of memory when loading a document.
        // When we load a document, various elements are temporarily stored in memory as the save operation occurs.
        // We can use this option to use a temporary folder in the local file system instead,
        // which will reduce our application's memory overhead.
        LoadOptions options = new LoadOptions();
        options.setTempFolder(getArtifactsDir() + "TempFiles");
        
        // The specified temporary folder must exist in the local file system before the load operation.
        Files.createDirectory(Paths.get(options.getTempFolder()));
        
        Document doc = new Document(getMyDir() + "Document.docx", options);
        
        // The folder will persist with no residual contents from the load operation.
        Assert.assertTrue(DocumentHelper.directoryGetFiles(options.getTempFolder(), "*.*").size() == 0);
      • getUpdateDirtyFields/setUpdateDirtyFields

        public boolean getUpdateDirtyFields() / public void setUpdateDirtyFields(boolean value)
        
        Specifies whether to update the fields with the dirty attribute.

        Example:

        Shows how to use special property for updating field result.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Give the document's built-in "Author" property value, and then display it with a field.
        doc.getBuiltInDocumentProperties().setAuthor("John Doe");
        FieldAuthor field = (FieldAuthor) builder.insertField(FieldType.FIELD_AUTHOR, true);
        
        Assert.assertFalse(field.isDirty());
        Assert.assertEquals("John Doe", field.getResult());
        
        // Update the property. The field still displays the old value.
        doc.getBuiltInDocumentProperties().setAuthor("John & Jane Doe");
        
        Assert.assertEquals("John Doe", field.getResult());
        
        // Since the field's value is out of date, we can mark it as "dirty".
        // This value will stay out of date until we update the field manually with the Field.Update() method.
        field.isDirty(true);
        
        OutputStream docStream = new FileOutputStream(getArtifactsDir() + "Filed.UpdateDirtyFields.docx");
        try {
            // If we save without calling an update method,
            // the field will keep displaying the out of date value in the output document.
            doc.save(docStream, SaveFormat.DOCX);
        
            // The LoadOptions object has an option to update all fields
            // marked as "dirty" when loading the document.
            LoadOptions options = new LoadOptions();
            options.setUpdateDirtyFields(updateDirtyFields);
        
            doc = new Document(String.valueOf(docStream), options);
        
            Assert.assertEquals("John & Jane Doe", doc.getBuiltInDocumentProperties().getAuthor());
        
            field = (FieldAuthor) doc.getRange().getFields().get(0);
        
            // Updating dirty fields like this automatically set their "IsDirty" flag to false.
            if (updateDirtyFields) {
                Assert.assertEquals("John & Jane Doe", field.getResult());
                Assert.assertFalse(field.isDirty());
            } else {
                Assert.assertEquals("John Doe", field.getResult());
                Assert.assertTrue(field.isDirty());
            }
        } finally {
            if (docStream != null) docStream.close();
        }
      • getWarningCallback/setWarningCallback

        public IWarningCallback getWarningCallback() / public void setWarningCallback(IWarningCallback value)
        
        Called during a load operation, when an issue is detected that might result in data or formatting fidelity loss.

        Example:

        Shows how to print and store warnings that occur during document loading.
        // Create a new LoadOptions object and set its WarningCallback attribute
            // as an instance of our IWarningCallback implementation.
            LoadOptions loadOptions = new LoadOptions();
            loadOptions.setWarningCallback(new DocumentLoadingWarningCallback());
        
            // Our callback will print all warnings that come up during the load operation.
            Document doc = new Document(getMyDir() + "Document.docx", loadOptions);
        
            ArrayList<WarningInfo> warnings = ((DocumentLoadingWarningCallback) loadOptions.getWarningCallback()).getWarnings();
            Assert.assertEquals(3, warnings.size());
        
        /// <summary>
        /// IWarningCallback that prints warnings and their details as they arise during document loading.
        /// </summary>
        private static class DocumentLoadingWarningCallback implements IWarningCallback {
            public void warning(WarningInfo info) {
                System.out.println(MessageFormat.format("Warning: {0}", info.getWarningType()));
                System.out.println(MessageFormat.format("\tSource: {0}", info.getSource()));
                System.out.println(MessageFormat.format("\tDescription: {0}", info.getDescription()));
                mWarnings.add(info);
            }
        
            public ArrayList<WarningInfo> getWarnings() {
                return mWarnings;
            }
        
            private final /*final*/ ArrayList<WarningInfo> mWarnings = new ArrayList<WarningInfo>();
        }
      • getWebRequestTimeout/setWebRequestTimeout

        public int getWebRequestTimeout() / public void setWebRequestTimeout(int value)
        
        The number of milliseconds to wait before the web request times out. The default value is 100000 milliseconds (100 seconds). The number of milliseconds that Aspose.Words waits for a response, when loading external resources (images, style sheets) linked in HTML and MHTML documents.