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
booleangetAllowTrailingWhitespaceForListItems()
void
           Allows to specify how numbered list items are recognized when document is imported from plain text format. The default value is true.
booleangetAnnotationsAtBlockLevel()
void
           Gets or sets a flag indicating whether cross structure annotation nodes can be added at block/cell/row level.
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.
booleangetConvertShapeToOfficeMath()
void
           Gets or sets whether to convert shapes with EquationXML to Office Math objects.
java.nio.charset.CharsetgetEncoding()
void
setEncoding(java.nio.charset.Charsetvalue)
           Gets or sets the encoding that will be used to load an HTML or TXT document if the encoding is not specified in HTML/TXT. Can be null. Default is null.
FontSettingsgetFontSettings()
void
           Allows to specify document font settings.
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_2007The 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 preffered 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.
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)
           Specifies HTML parser to parse conditional comments exactly like <!--[if gte vml 1]> and not to parse conditional comments exactly like <![if !vml]>.
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.
      • 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.
      • 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.
    • Property Getters/Setters Detail

      • getAllowTrailingWhitespaceForListItems/setAllowTrailingWhitespaceForListItems

        public boolean getAllowTrailingWhitespaceForListItems() / public void setAllowTrailingWhitespaceForListItems(boolean value)
        
        Allows to specify how numbered list items are recognized when document is imported from plain text format. The default value is true.

        This property is used only when loading plain text documents.

        If set to true, lists recognition algorithm allows list numbers to end with either dot or whitespace character.

        If this option is set to false then the list item is only recognized as such if the leading number is ending with dot "." symbol.

      • getAnnotationsAtBlockLevel/setAnnotationsAtBlockLevel

        public boolean getAnnotationsAtBlockLevel() / public void setAnnotationsAtBlockLevel(boolean value)
        
        Gets or sets a flag indicating whether cross structure annotation nodes can be added at block/cell/row level. Currently only bookmarks are affected by this option.
      • 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:

        Opens an HTML document with images from a stream using a base URI.
        // We are opening this HTML file:
        //    <html>
        //    <body>
        //    <p>Simple file.</p>
        //    <p><img src="Aspose.Words.gif" width="80" height="60"></p>
        //    </body>
        //    </html>
        String fileName = getMyDir() + "Document.OpenFromStreamWithBaseUri.html";
        
        // Open the stream.
        InputStream stream = new FileInputStream(fileName);
        
        // Open the document. Note the Document constructor detects HTML format automatically.
        // Pass the URI of the base folder so any images with relative URIs in the HTML document can be found.
        LoadOptions loadOptions = new LoadOptions();
        loadOptions.setBaseUri(getMyDir());
        Document doc = new Document(stream, loadOptions);
        
        // You can close the stream now, it is no longer needed because the document is in memory.
        stream.close();
        
        // Save in the DOC format.
        doc.save(getMyDir() + "\\Artifacts\\Document.OpenFromStreamWithBaseUri.doc");
      • getConvertShapeToOfficeMath/setConvertShapeToOfficeMath

        public boolean getConvertShapeToOfficeMath() / public void setConvertShapeToOfficeMath(boolean value)
        
        Gets or sets whether to convert shapes with EquationXML to Office Math objects.
      • 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 or TXT document if the encoding is not specified in HTML/TXT. Can be null. Default is null.

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

        If encoding is not specified in HTML/TXT and this property is null, then the system will try to automatically detect the encoding.

      • 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.

      • getLanguagePreferences

        public LanguagePreferences getLanguagePreferences()
        
        Gets language preferences that will be used when document is loading.
      • 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.

      • 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_2007The 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.
      • 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.

      • getPreferredControlType/setPreferredControlType

        public int getPreferredControlType() / public void setPreferredControlType(int value)
        
        Gets or sets preffered 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 preffered 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("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.

      • 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.
      • getSupportVml/setSupportVml

        public boolean getSupportVml() / public void setSupportVml(boolean value)
        
        Specifies HTML parser to parse conditional comments exactly like <!--[if gte vml 1]> and not to parse conditional comments exactly like <![if !vml]>.

        Example:

        Shows how to parse HTML document with conditional comments like "<!--[if gte vml 1]>" and "<![if !vml]>"
        HtmlLoadOptions loadOptions = new HtmlLoadOptions();
        
        //If value is true, then we parse "<!--[if gte vml 1]>", else parse "<![if !vml]>"
        loadOptions.setSupportVml(true);
        //Wait for a response, when loading external resources
        loadOptions.setWebRequestTimeout(1000);
        
        Document doc = new Document(getMyDir() + "Shape.VmlAndDml.htm", loadOptions);
        doc.save(getMyDir() + "\\Artifacts\\Shape.VmlAndDml.docx");
      • getUpdateDirtyFields/setUpdateDirtyFields

        public boolean getUpdateDirtyFields() / public void setUpdateDirtyFields(boolean value)
        
        Specifies whether to update the fields with the dirty attribute.
      • 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.
      • 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.