LoadOptions
Inheritance: java.lang.Object
public class LoadOptions
Provides options that are used to open a file.
The LoadOptions class encapsulates various settings and parameters that can be used to specify how a file should be opened and loaded in the GroupDocs.Viewer component. For details, see this page and its children.
Example usage:
LoadOptions options = new LoadOptions();
options.setPassword("myPassword");
options.setFileType(PDF);
options.setCharset(Charset.forName("UTF-8"));
try (Viewer viewer = new Viewer(pdfFileInputStream, options)) {
// Use the viewer object for further operations
}
Constructors
Constructor | Description |
---|---|
LoadOptions() | Initializes a new instance of the LoadOptions class. |
LoadOptions(FileType fileType) | Initializes a new instance of the LoadOptions class. |
Fields
Field | Description |
---|---|
DEFAULT_URL_CONNECT_TIMEOUT | |
DEFAULT_URL_READ_TIMEOUT | |
_tryRepair |
Methods
Method | Description |
---|---|
isTryRepair() | When enabled, GroupDocs.Viewer tries to repair structural corruption in PDF documents. |
setTryRepair(boolean tryRepair) | When enabled, GroupDocs.Viewer tries to repair structural corruption in PDF documents. |
getFileType() | Gets the type of the file to open. |
setFileType(FileType value) | Sets the type of the file to open. |
getPassword() | Gets the password for opening an encrypted file. |
setPassword(String value) | Sets the password for opening an encrypted file. |
getCharset() | The charset used when opening text-based files or email messages such as FileType.CSV, FileType.TXT, and FileType.MSG. |
setCharset(Charset value) | The charset used when opening text-based files or email messages such as FileType.CSV, FileType.TXT, and FileType.MSG. |
isDetectCharset() | This option enables FileType.TXT, FileType.TSV, and FileType.CSV files charset detection. |
setDetectCharset(boolean detectCharset) | This option enables FileType.TXT, FileType.TSV, and FileType.CSV files charset detection. |
getResourceLoadingTimeout() | Gets the timeout for loading external resources. |
setResourceLoadingTimeout(int resourceLoadingTimeout) | Sets the timeout for loading external resources, such as graphics. |
getUrlConnectTimeout() | Gets the connection timeout for creating a Viewer using java.net.URL to load a document. |
setUrlConnectTimeout(int urlConnectTimeout) | Sets the connection timeout for creating a Viewer using java.net.URL to load a document. |
getUrlReadTimeout() | Gets the read timeout for creating a Viewer using java.net.URL to load a document. |
setUrlReadTimeout(int urlReadTimeout) | Sets the read timeout for creating a Viewer using java.net.URL to load a document. |
getArchiveSecurityOptions() | Gets the security options to control the process of extracting archives. |
setArchiveSecurityOptions(ArchiveSecurityOptions archiveSecurityOptions) | Sets the security options to control the process of extracting archives. |
isSkipExternalResources() | When set to true, all external resources such as images will not be loaded except #getWhitelistedResources().getWhitelistedResources(). |
setSkipExternalResources(boolean skipExternalResources) | When set to true, all external resources such as images will not be loaded except #getWhitelistedResources().getWhitelistedResources(). |
getWhitelistedResources() | The list of URL fragments corresponding to external resources that should be loaded when #isSkipExternalResources().isSkipExternalResources() is set to true . |
setWhitelistedResources(List |
Sets the list of URL fragments corresponding to external resources that should be loaded when #isSkipExternalResources().isSkipExternalResources() is set to true . |
LoadOptions()
public LoadOptions()
Initializes a new instance of the LoadOptions class.
For code example, see the documentation.
LoadOptions(FileType fileType)
public LoadOptions(FileType fileType)
Initializes a new instance of the LoadOptions class.
For code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
fileType | FileType | The type of the file to open. |
DEFAULT_URL_CONNECT_TIMEOUT
public static final int DEFAULT_URL_CONNECT_TIMEOUT
DEFAULT_URL_READ_TIMEOUT
public static final int DEFAULT_URL_READ_TIMEOUT
_tryRepair
public boolean _tryRepair
isTryRepair()
public boolean isTryRepair()
When enabled, GroupDocs.Viewer tries to repair structural corruption in PDF documents. Default value is false.
This feature addresses the following issues in a PDF document:
- Broken references within the document (incorrect object offsets in the Cross-reference list).
- Missing critical elements like root object, page object, or page content.
- Circular references (Form X-object referencing itself).
Returns: boolean
setTryRepair(boolean tryRepair)
public void setTryRepair(boolean tryRepair)
When enabled, GroupDocs.Viewer tries to repair structural corruption in PDF documents. Default value is false.
This feature addresses the following issues in a PDF document:
- Broken references within the document (incorrect object offsets in the Cross-reference list).
- Missing critical elements like root object, page object, or page content.
- Circular references (Form X-object referencing itself).
Parameters:
Parameter | Type | Description |
---|---|---|
tryRepair | boolean |
getFileType()
public final FileType getFileType()
Gets the type of the file to open.
For code example, see the documentation.
Returns: FileType - the file type.
setFileType(FileType value)
public final void setFileType(FileType value)
Sets the type of the file to open.
For code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
value | FileType | The file type. |
getPassword()
public final String getPassword()
Gets the password for opening an encrypted file.
For code example, see the documentation.
Returns: java.lang.String - the password for opening the file.
setPassword(String value)
public final void setPassword(String value)
Sets the password for opening an encrypted file.
For code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | The password for opening the file. |
getCharset()
public final Charset getCharset()
The charset used when opening text-based files or email messages such as FileType.CSV, FileType.TXT, and FileType.MSG.
Default value is java.nio.charset.StandardCharsets#UTF_8.UTF_8. For code example, see the documentation.
Learn more
- Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files
- Render text documents as HTML, PDF, and image files
- Render email messages as HTML, PDF, PNG, and JPEG files
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setCharset(StandardCharsets.US_ASCII); // Set the charset
try (Viewer viewer = new Viewer("message.txt", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Returns: java.nio.charset.Charset
setCharset(Charset value)
public final void setCharset(Charset value)
The charset used when opening text-based files or email messages such as FileType.CSV, FileType.TXT, and FileType.MSG.
Default value is java.nio.charset.StandardCharsets#UTF_8.UTF_8. For code example, see the documentation.
Learn more
- Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files
- Render text documents as HTML, PDF, and image files
- Render email messages as HTML, PDF, PNG, and JPEG files
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setCharset(StandardCharsets.US_ASCII); // Set the charset
try (Viewer viewer = new Viewer("message.txt", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.nio.charset.Charset |
isDetectCharset()
public boolean isDetectCharset()
This option enables FileType.TXT, FileType.TSV, and FileType.CSV files charset detection. In case the charset can’t be detected the default getCharset() is used.
Learn more about rendering text and tab/comma delimited files
- Render text documents as HTML, PDF, and image files
- Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files
If the encoding cannot be detected, the default is used. For code example, see the documentation.
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setDetectCharset(true); // Enable encoding detection
try (Viewer viewer = new Viewer("employees.csv", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Returns: boolean
setDetectCharset(boolean detectCharset)
public void setDetectCharset(boolean detectCharset)
This option enables FileType.TXT, FileType.TSV, and FileType.CSV files charset detection. In case the charset can’t be detected the default getCharset() is used.
Learn more about rendering text and tab/comma delimited files
- Render text documents as HTML, PDF, and image files
- Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files
If the encoding cannot be detected, the default is used. For code example, see the documentation.
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setDetectCharset(true); // Enable encoding detection
try (Viewer viewer = new Viewer("employees.csv", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Parameters:
Parameter | Type | Description |
---|---|---|
detectCharset | boolean |
getResourceLoadingTimeout()
public int getResourceLoadingTimeout()
Gets the timeout for loading external resources.
Note: The default value is 10 seconds.
This option applies to the following file formats:
Learn more about options to manage external resources:
The default value is 30 seconds. For code example, see the documentation.
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setResourceLoadingTimeout(5000); // Set resource loading timeout to 5 seconds
try (Viewer viewer = new Viewer("business-flyer.docx", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Returns: int
setResourceLoadingTimeout(int resourceLoadingTimeout)
public void setResourceLoadingTimeout(int resourceLoadingTimeout)
Sets the timeout for loading external resources, such as graphics.
Note: The default value is 30 seconds.
This option is supported for Word Processing documents that contain external resources. The default value is 30 seconds. For code example, see the documentation.
Parameters:
Parameter | Type | Description |
---|---|---|
resourceLoadingTimeout | int | The loading timeout, milliseconds. |
getUrlConnectTimeout()
public int getUrlConnectTimeout()
Gets the connection timeout for creating a Viewer using java.net.URL to load a document.
Note: The default value is 5 seconds.
Returns: int - the connection timeout.
setUrlConnectTimeout(int urlConnectTimeout)
public void setUrlConnectTimeout(int urlConnectTimeout)
Sets the connection timeout for creating a Viewer using java.net.URL to load a document.
Note: The default value is 5 seconds.
Parameters:
Parameter | Type | Description |
---|---|---|
urlConnectTimeout | int | The connection timeout. |
getUrlReadTimeout()
public int getUrlReadTimeout()
Gets the read timeout for creating a Viewer using java.net.URL to load a document.
Note: The default value is 30 seconds.
Returns: int - the read timeout.
setUrlReadTimeout(int urlReadTimeout)
public void setUrlReadTimeout(int urlReadTimeout)
Sets the read timeout for creating a Viewer using java.net.URL to load a document.
Note: The default value is 30 seconds.
Parameters:
Parameter | Type | Description |
---|---|---|
urlReadTimeout | int | The read timeout. |
getArchiveSecurityOptions()
public ArchiveSecurityOptions getArchiveSecurityOptions()
Gets the security options to control the process of extracting archives.
Note: Not each archive type supports all options.
Returns: com.groupdocs.viewer.options.ArchiveSecurityOptions - the options object to configure the process of extracting archives.
setArchiveSecurityOptions(ArchiveSecurityOptions archiveSecurityOptions)
public void setArchiveSecurityOptions(ArchiveSecurityOptions archiveSecurityOptions)
Sets the security options to control the process of extracting archives.
Note: Not each archive type supports all options.
Parameters:
Parameter | Type | Description |
---|---|---|
archiveSecurityOptions | com.groupdocs.viewer.options.ArchiveSecurityOptions | The options object to configure the process of extracting archives. |
isSkipExternalResources()
public boolean isSkipExternalResources()
When set to true, all external resources such as images will not be loaded except #getWhitelistedResources().getWhitelistedResources().
This option applies to the following file formats:
Learn more about options to manage external resources:
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setSkipExternalResources(true); // Skip loading of external resources
try (Viewer viewer = new Viewer("business-flyer.docx", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Returns: boolean
setSkipExternalResources(boolean skipExternalResources)
public void setSkipExternalResources(boolean skipExternalResources)
When set to true, all external resources such as images will not be loaded except #getWhitelistedResources().getWhitelistedResources().
This option applies to the following file formats:
Learn more about options to manage external resources:
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setSkipExternalResources(true); // Skip loading of external resources
try (Viewer viewer = new Viewer("business-flyer.docx", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Parameters:
Parameter | Type | Description |
---|---|---|
skipExternalResources | boolean | The flag to enable or disable loading of external resources. |
getWhitelistedResources()
public List<String> getWhitelistedResources()
The list of URL fragments corresponding to external resources that should be loaded when #isSkipExternalResources().isSkipExternalResources() is set to true
.
This option applies to the following file formats:
Learn more about options to manage external resources:
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setSkipExternalResources(true); // Skip loading of external resources
loadOptions.getWhitelistedResources().add("avatars.githubusercontent.com"); // Enable loading of external resources that have 'avatars.githubusercontent.com' fragment in resource URL.
try (Viewer viewer = new Viewer("business-flyer.docx", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Returns: java.util.List<java.lang.String>
setWhitelistedResources(List whitelistedResources)
public void setWhitelistedResources(List<String> whitelistedResources)
Sets the list of URL fragments corresponding to external resources that should be loaded when #isSkipExternalResources().isSkipExternalResources() is set to true
.
This option applies to the following file formats:
Learn more about options to manage external resources:
Example:
LoadOptions loadOptions = new LoadOptions();
loadOptions.setSkipExternalResources(true); // Skip loading of external resources
loadOptions.setWhitelistedResources(Arrays.asList("avatars.githubusercontent.com")); // Enable loading of external resources that have 'avatars.githubusercontent.com' fragment in resource URL.
try (Viewer viewer = new Viewer("business-flyer.docx", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Parameters:
Parameter | Type | Description |
---|---|---|
whitelistedResources | java.util.List<java.lang.String> | The list of URL fragments corresponding to external resources that should be loaded. |