java.lang.Objectcom.aspose.words.LoadOptions
public class LoadOptions
Example: Example:
Document doc = new Document(getMyDir() + "Document.LoadEncrypted.doc", new LoadOptions("qwerty"));
// 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() + "Document.OpenFromStreamWithBaseUri Out.doc");
Constructor Summary |
---|
LoadOptions()
Initializes a new instance of this class with default values. |
LoadOptions(java.lang.String password)
A shortcut to initialize a new instance of this class with the specified password to load an encrypted document. |
LoadOptions(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. |
Property Getters/Setters Summary | ||
---|---|---|
java.lang.String | getBaseUri() | |
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. | ||
java.nio.charset.Charset | getEncoding() | |
void | setEncoding(java.nio.charset.Charset value) | |
Gets or sets the encoding that will be used to load an HTML document if the encoding is not specified in HTML. Can be null. Default is null. | ||
int | getLoadFormat() | |
void | setLoadFormat(int value) | |
Specifies the format of the document to be loaded.
Default is |
||
java.lang.String | getPassword() | |
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. | ||
IResourceLoadingCallback | getResourceLoadingCallback() | |
void | setResourceLoadingCallback(IResourceLoadingCallback value) | |
Allows to control how external resources (images, style sheets) are loaded when a document is imported from HTML, MHTML. | ||
IWarningCallback | getWarningCallback() | |
void | setWarningCallback(IWarningCallback value) | |
Called during a load operation, when an issue is detected that might result in data or formatting fidelity loss. |
Constructor Detail |
---|
public LoadOptions()
public LoadOptions(java.lang.String password)
password
- The password to open an encrypted document. Can be null or empty string.Example:
Loads a Microsoft Word document encrypted with a password.Document doc = new Document(getMyDir() + "Document.LoadEncrypted.doc", new LoadOptions("qwerty"));
public LoadOptions(int loadFormat, java.lang.String password, java.lang.String baseUri)
loadFormat
- A 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 insert the HTML contents from a web page into a new document.// The url of the page to load URL url = new URL("http://www.aspose.com/"); // The easiest way to load our document from the internet is make use of the URLConnection class. URLConnection webClient = url.openConnection(); // Download the bytes from the location referenced by the URL. InputStream inputStream = webClient.getInputStream(); // Convert the input stream to a byte array. int pos; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((pos = inputStream.read()) != -1) bos.write(pos); byte[] dataBytes = bos.toByteArray(); // Wrap the bytes representing the document in memory into a stream object. ByteArrayInputStream byteStream = new ByteArrayInputStream(dataBytes); // The baseUri property should be set to ensure any relative img paths are retrieved correctly. LoadOptions options = new LoadOptions(LoadFormat.HTML, "", url.getPath()); // Load the HTML document from stream and pass the LoadOptions object. Document doc = new Document(byteStream, options); // Save the document to disk. // The extension of the filename can be changed to save the document into other formats. e.g PDF, DOCX, ODT, RTF. doc.save(getMyDir() + "Document.HtmlPageFromWebpage Out.doc");
Property Getters/Setters Detail |
---|
getBaseUri/setBaseUri | |
public java.lang.String getBaseUri() / public void setBaseUri(java.lang.String value) |
This property is used to resolve relative URIs into absolute in the following cases:
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() + "Document.OpenFromStreamWithBaseUri Out.doc");
getEncoding/setEncoding | |
public java.nio.charset.Charset getEncoding() / public void setEncoding(java.nio.charset.Charset value) |
This property is used only when loading HTML documents.
If encoding is not specified in HTML and this property is null
, then the system will try to
automatically detect the encoding.
getLoadFormat/setLoadFormat | |
public int getLoadFormat() / public void setLoadFormat(int value) |
It is recommended that you specify the
getPassword/setPassword | |
public java.lang.String getPassword() / public void setPassword(java.lang.String value) |
You need to know the password to open an encrypted document. If the document is not encrypted, set this to null or empty string.
getResourceLoadingCallback/setResourceLoadingCallback | |
public IResourceLoadingCallback getResourceLoadingCallback() / public void setResourceLoadingCallback(IResourceLoadingCallback value) |
getWarningCallback/setWarningCallback | |
public IWarningCallback getWarningCallback() / public void setWarningCallback(IWarningCallback value) |