public class LoadOptions extends Object
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
}
Viewer| Modifier and Type | Field and Description |
|---|---|
boolean |
_tryRepair |
static int |
DEFAULT_URL_CONNECT_TIMEOUT |
static int |
DEFAULT_URL_READ_TIMEOUT |
| Constructor and Description |
|---|
LoadOptions()
Initializes a new instance of the
LoadOptions class. |
LoadOptions(FileType fileType)
Initializes a new instance of the
LoadOptions class. |
| Modifier and Type | Method and Description |
|---|---|
com.groupdocs.viewer.options.ArchiveSecurityOptions |
getArchiveSecurityOptions()
Gets the security options to control the process of extracting archives.
|
Charset |
getCharset()
The charset used when opening text-based files or email messages such as
FileType.CSV,
FileType.TXT,
and FileType.MSG. |
FileType |
getFileType()
Gets the type of the file to open.
|
String |
getPassword()
Gets the password for opening an encrypted file.
|
int |
getResourceLoadingTimeout()
Gets the timeout for loading external resources.
|
int |
getUrlConnectTimeout()
|
int |
getUrlReadTimeout()
|
List<String> |
getWhitelistedResources()
The list of URL fragments corresponding to external resources that should be loaded when
isSkipExternalResources() is set to true. |
boolean |
isDetectCharset()
|
boolean |
isSkipExternalResources()
When set to
getWhitelistedResources(). |
boolean |
isTryRepair()
When enabled, GroupDocs.Viewer tries to repair structural corruption in PDF documents.
|
void |
setArchiveSecurityOptions(com.groupdocs.viewer.options.ArchiveSecurityOptions archiveSecurityOptions)
Sets the security options to control the process of extracting archives.
|
void |
setCharset(Charset value)
The charset used when opening text-based files or email messages such as
FileType.CSV,
FileType.TXT,
and FileType.MSG. |
void |
setDetectCharset(boolean detectCharset)
|
void |
setFileType(FileType value)
Sets the type of the file to open.
|
void |
setPassword(String value)
Sets the password for opening an encrypted file.
|
void |
setResourceLoadingTimeout(int resourceLoadingTimeout)
Sets the timeout for loading external resources, such as graphics.
|
void |
setSkipExternalResources(boolean skipExternalResources)
When set to
getWhitelistedResources(). |
void |
setTryRepair(boolean tryRepair)
When enabled, GroupDocs.Viewer tries to repair structural corruption in PDF documents.
|
void |
setUrlConnectTimeout(int urlConnectTimeout)
|
void |
setUrlReadTimeout(int urlReadTimeout)
|
void |
setWhitelistedResources(List<String> whitelistedResources)
Sets the list of URL fragments corresponding to external resources that should be loaded when
isSkipExternalResources() is set to true. |
public boolean _tryRepair
public static final int DEFAULT_URL_CONNECT_TIMEOUT
public static final int DEFAULT_URL_READ_TIMEOUT
public LoadOptions()
Initializes a new instance of the LoadOptions class.
For code example, see the documentation.
public LoadOptions(FileType fileType)
Initializes a new instance of the LoadOptions class.
For code example, see the documentation.
fileType - The type of the file to open.IllegalArgumentException - If the fileType parameter is null.public com.groupdocs.viewer.options.ArchiveSecurityOptions getArchiveSecurityOptions()
Gets the security options to control the process of extracting archives.
Note: Not each archive type supports all options.
public final Charset getCharset()
The charset used when opening text-based files or email messages such as
FileType.CSV,
FileType.TXT,
and FileType.MSG.
StandardCharsets.UTF_8.
For code example, see the documentation.
Learn more
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);
}
public final FileType getFileType()
Gets the type of the file to open.
For code example, see the documentation.
FileTypepublic final String getPassword()
Gets the password for opening an encrypted file.
For code example, see the documentation.
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);
}
public int getUrlConnectTimeout()
Gets the connection timeout for creating a Viewer using URL to load a document.
Note: The default value is 5 seconds.
public int getUrlReadTimeout()
Gets the read timeout for creating a Viewer using URL to load a document.
Note: The default value is 30 seconds.
public List<String> getWhitelistedResources()
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);
}
public boolean isDetectCharset()
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
If the encoding cannot be detected, the default
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);
}
public boolean isSkipExternalResources()
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);
}
public boolean isTryRepair()
This feature addresses the following issues in a PDF document:
public void setArchiveSecurityOptions(com.groupdocs.viewer.options.ArchiveSecurityOptions archiveSecurityOptions)
Sets the security options to control the process of extracting archives.
Note: Not each archive type supports all options.
archiveSecurityOptions - The options object to configure the process of extracting archives.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.
StandardCharsets.UTF_8.
For code example, see the documentation.
Learn more
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);
}
public void setDetectCharset(boolean detectCharset)
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
If the encoding cannot be detected, the default
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);
}
public final void setFileType(FileType value)
Sets the type of the file to open.
For code example, see the documentation.
value - The file type.FileTypepublic final void setPassword(String value)
Sets the password for opening an encrypted file.
For code example, see the documentation.
value - The password for opening the file.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.
resourceLoadingTimeout - The loading timeout, milliseconds.public void setSkipExternalResources(boolean skipExternalResources)
When set to 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);
}
skipExternalResources - The flag to enable or disable loading of external resources.public void setTryRepair(boolean tryRepair)
This feature addresses the following issues in a PDF document:
public void setUrlConnectTimeout(int urlConnectTimeout)
Sets the connection timeout for creating a Viewer using URL to load a document.
Note: The default value is 5 seconds.
urlConnectTimeout - The connection timeout.public void setUrlReadTimeout(int urlReadTimeout)
Sets the read timeout for creating a Viewer using URL to load a document.
Note: The default value is 30 seconds.
urlReadTimeout - The read timeout.public void setWhitelistedResources(List<String> whitelistedResources)
Sets the list of URL fragments corresponding to external resources that should be loaded when 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);
}
whitelistedResources - The list of URL fragments corresponding to external resources that should be loaded.Copyright © 2025. All rights reserved.