public class Viewer extends Object implements Closeable
The Viewer class is the entry point for rendering documents using the GroupDocs.Viewer component. It provides methods and options to load documents from various sources, customize the rendering process, and retrieve the rendered output in different formats.
Example usage:
try (Viewer viewer = new Viewer("source.pdf")) {
viewer.view(new PngViewOptions("result-page{0}.png"));
}
PngViewOptions| Modifier and Type | Field and Description |
|---|---|
static String |
FILE_READER |
static String |
LOAD_OPTIONS |
static String |
OPTIONS |
static String |
SETTINGS |
| Constructor and Description |
|---|
Viewer(FileReader fileReader,
LoadOptions loadOptions,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(FileReader fileReader,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(InputStream fileStream)
Initializes a new instance of the Viewer class.
|
Viewer(InputStream fileStream,
boolean leaveOpen)
Initializes a new instance of the Viewer class.
|
Viewer(InputStream fileStream,
LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
|
Viewer(InputStream fileStream,
LoadOptions loadOptions,
boolean leaveOpen)
Initializes a new instance of the Viewer class.
|
Viewer(InputStream fileStream,
LoadOptions loadOptions,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(InputStream fileStream,
LoadOptions loadOptions,
ViewerSettings settings,
boolean leaveOpen)
Initializes new instance of Viewer class.
|
Viewer(InputStream fileStream,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(InputStream fileStream,
ViewerSettings settings,
boolean leaveOpen)
Initializes a new instance of the Viewer class.
|
Viewer(Path filePath)
Initializes a new instance of the Viewer class.
|
Viewer(Path filePath,
LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
|
Viewer(Path filePath,
LoadOptions loadOptions,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(Path filePath,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(String filePath)
Initializes a new instance of the Viewer class.
|
Viewer(String filePath,
LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
|
Viewer(String filePath,
LoadOptions loadOptions,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(String filePath,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(URL url)
Initializes a new instance of the Viewer class.
|
Viewer(URL url,
LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
|
Viewer(URL url,
LoadOptions loadOptions,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
Viewer(URL url,
ViewerSettings settings)
Initializes a new instance of the Viewer class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases the file stream and managed internal resources.
|
com.groupdocs.viewer.fonts.IFontInfo[] |
getAllFonts()
Returns all fonts used in the loaded documents, including those embedded
inside the document itself and those system fonts installed in the OS and used in the document.
|
List<Attachment> |
getAttachments()
Returns attachments contained by the document.
|
FileInfo |
getFileInfo()
Returns information about the file, such as file type and a flag that indicates if the file is encrypted.
|
ViewInfo |
getViewInfo(ViewInfoOptions options)
Returns information about the view and document specific information.
|
protected void |
initViewerFromUrl(URL url,
int urlConnectTimeout,
int urlReadTimeout) |
void |
saveAttachment(Attachment attachment,
OutputStream destination)
Saves an attachment file to the destination stream.
|
void |
search(com.groupdocs.viewer.options.SearchHighlightOptions options)
Performs a text search and highlights matches (if found) in the loaded document
according to the provided options.
|
void |
view(ViewOptions options)
Creates a view of all document pages.
|
void |
view(ViewOptions options,
int... pageNumbers)
Creates a view of specific document pages.
|
public static final String FILE_READER
public static final String LOAD_OPTIONS
public static final String OPTIONS
public static final String SETTINGS
public Viewer(FileReader fileReader, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Provides functionality to load and view documents using GroupDocs.Viewer.
Note: Ensure that the file reader, load options, and settings are properly configured for accurate document processing.
fileReader - The file reader.loadOptions - The load options.settings - The Viewer settings.IllegalArgumentException - Thrown when fileReader is null.IllegalArgumentException - Thrown when loadOptions is null.IllegalArgumentException - Thrown when settings is null.FileReader,
LoadOptions,
ViewerSettingspublic Viewer(FileReader fileReader, ViewerSettings settings)
Initializes a new instance of the Viewer class.
This constructor allows you to create a Viewer object to view a document from a FileReader with the specified ViewerSettings.
fileReader - The FileReader containing the document to be loaded into the Viewer.settings - The ViewerSettings to be applied to the Viewer.IllegalArgumentException - Thrown when fileReader is null.IllegalArgumentException - Thrown when settings is null.public Viewer(InputStream fileStream)
Initializes a new instance of the Viewer class.
More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
fileStream - The method that returns a readable stream.IllegalArgumentException - Thrown when fileStream is null.public Viewer(InputStream fileStream, boolean leaveOpen)
Initializes a new instance of the Viewer class.
Learn morefileStream - The file stream.leaveOpen - true to leave the stream open after the Viewer object is disposed; otherwise, false.IllegalArgumentException - Thrown when fileStream is null.public Viewer(InputStream fileStream, LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
Learn morefileStream - The readable stream.loadOptions - The document load options.IllegalArgumentException - Thrown when fileStream is null.IllegalArgumentException - Thrown when loadOptions is null.public Viewer(InputStream fileStream, LoadOptions loadOptions, boolean leaveOpen)
Initializes a new instance of the Viewer class.
Learn morefileStream - The file stream.loadOptions - The document load options.leaveOpen - true to leave the stream open after the Viewer object is disposed; otherwise, false.IllegalArgumentException - Thrown when fileStream is null.IllegalArgumentException - Thrown when loadOptions is null.public Viewer(InputStream fileStream, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn morefileStream - The file stream.loadOptions - The document load options.settings - The Viewer settings.IllegalArgumentException - Thrown when fileStream is null.IllegalArgumentException - Thrown when loadOptions is null.IllegalArgumentException - Thrown when settings is null.public Viewer(InputStream fileStream, LoadOptions loadOptions, ViewerSettings settings, boolean leaveOpen)
Initializes new instance of Viewer class.
Learn morefileStream - The file stream.loadOptions - The document load options.settings - The Viewer settings.leaveOpen - true to leave the stream open after the Viewer object is disposed; otherwise, false.public Viewer(InputStream fileStream, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn morefileStream - The file stream.settings - The Viewer settings.IllegalArgumentException - Thrown when fileStream is null.IllegalArgumentException - Thrown when settings is null.public Viewer(InputStream fileStream, ViewerSettings settings, boolean leaveOpen)
Initializes a new instance of the Viewer class.
Learn morefileStream - The file stream.settings - The Viewer settings.leaveOpen - true to leave the stream open after the Viewer object is disposed; otherwise, false.IllegalArgumentException - Thrown when fileStream is null.IllegalArgumentException - Thrown when settings is null.public Viewer(Path filePath) throws FileNotFoundException
Initializes a new instance of the Viewer class.
Learn morefilePath - The path to the file to render.FileNotFoundException - Thrown when the file cannot be found or cannot be read.IllegalArgumentException - Thrown when filePath is null or empty.public Viewer(Path filePath, LoadOptions loadOptions) throws FileNotFoundException
Initializes a new instance of the Viewer class.
Learn morefilePath - The path to the file to render.loadOptions - The document load options.FileNotFoundException - Thrown when the file cannot be found or cannot be read.IllegalArgumentException - Thrown when filePath is null or empty.IllegalArgumentException - Thrown when loadOptions is null.public Viewer(Path filePath, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn morefilePath - The path to the file to render.loadOptions - The document load options.settings - The Viewer settings.IllegalArgumentException - Thrown when filePath is null or empty.IllegalArgumentException - Thrown when loadOptions is null.IllegalArgumentException - Thrown when settings is null.public Viewer(Path filePath, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn morefilePath - The path to the file to render.settings - The Viewer settings.IllegalArgumentException - Thrown when filePath is null or empty.IllegalArgumentException - Thrown when settings is null.public Viewer(String filePath) throws FileNotFoundException
Initializes a new instance of the Viewer class.
Learn more:filePath - The path to the file to render.FileNotFoundException - Thrown when the file cannot be found or read.IllegalArgumentException - Thrown when filePath is null or empty.public Viewer(String filePath, LoadOptions loadOptions) throws FileNotFoundException
Initializes a new instance of the Viewer class.
Learn morefilePath - The path to the file to render.loadOptions - The document load options.FileNotFoundException - Thrown when the file cannot be found or cannot be read.IllegalArgumentException - Thrown when filePath is null or empty.IllegalArgumentException - Thrown when loadOptions is null.public Viewer(String filePath, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn morefilePath - The path to the file to render.loadOptions - The document load options.settings - The Viewer settings.IllegalArgumentException - Thrown when filePath is null or empty.IllegalArgumentException - Thrown when loadOptions is null.IllegalArgumentException - Thrown when settings is null.public Viewer(String filePath, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn morefilePath - The path to the file to render.settings - The Viewer settings.IllegalArgumentException - Thrown when filePath is null or empty.IllegalArgumentException - Thrown when settings is null.public Viewer(URL url)
Initializes a new instance of the Viewer class.
More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
url - A URL to a file that should be loaded into the Viewer.IllegalArgumentException - Thrown when url is null.public Viewer(URL url, LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
Learn moreurl - A URL to a file that should be loaded into the Viewer.loadOptions - The document load options.IllegalArgumentException - Thrown when url is null.IllegalArgumentException - Thrown when loadOptions is null.public Viewer(URL url, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn moreurl - A URL to a file that should be loaded into the Viewer.loadOptions - The document load options.settings - The Viewer settings.IllegalArgumentException - Thrown when url is null.IllegalArgumentException - Thrown when loadOptions is null.IllegalArgumentException - Thrown when settings is null.public Viewer(URL url, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn moreurl - A URL to a file that should be loaded into the Viewer.settings - The Viewer settings.IllegalArgumentException - Thrown when url is null.IllegalArgumentException - Thrown when settings is null.public final void close()
Releases the file stream and managed internal resources.
close in interface Closeableclose in interface AutoCloseablepublic com.groupdocs.viewer.fonts.IFontInfo[] getAllFonts()
throws Exception
For details, see the documentation.
public final List<Attachment> getAttachments() throws PasswordRequiredException, IncorrectPasswordException
Returns attachments contained by the document.
Learn more:PasswordRequiredException - Thrown when a password is required to open the document.IncorrectPasswordException - Thrown when the specified password is incorrect.public FileInfo getFileInfo()
Returns information about the file, such as file type and a flag that indicates if the file is encrypted.
Learn more:FileInfopublic final ViewInfo getViewInfo(ViewInfoOptions options) throws IllegalArgumentException, PasswordRequiredException, IncorrectPasswordException
Returns information about the view and document specific information.
Learn more:options - The view info options.IllegalArgumentException - Thrown when options is null.PasswordRequiredException - Thrown when a password is required to open the document.IncorrectPasswordException - Thrown when the specified password is incorrect.protected void initViewerFromUrl(URL url, int urlConnectTimeout, int urlReadTimeout)
public void saveAttachment(Attachment attachment, OutputStream destination)
Saves an attachment file to the destination stream.
Learn more:attachment - The attachment.destination - The writable stream.IllegalArgumentException - Thrown when attachmentId is null or empty.IllegalArgumentException - Thrown when destination is null.PasswordRequiredException - Thrown when a password is required to open the document.IncorrectPasswordException - Thrown when the specified password is incorrect.GroupDocsViewerException - Thrown when the attachment could not be found.public void search(com.groupdocs.viewer.options.SearchHighlightOptions options)
throws Exception
options - Search and highlight options, including a text phrase to search. Cannot be null.IllegalArgumentException - Is thrown when the options argument is null.IllegalStateException - Is thrown when the loaded document is invalid or improperly loaded.Exceptionpublic final void view(ViewOptions options)
Creates a view of all document pages.
Learn moreoptions - The view options.IllegalArgumentException - Thrown when options is null.PasswordRequiredException - Thrown when a password is required to open the document.IncorrectPasswordException - Thrown when the specified password is incorrect.GroupDocsViewerException - Thrown when the attachment could not be found.public final void view(ViewOptions options, int... pageNumbers)
Creates a view of specific document pages.
Learn moreoptions - The view options.pageNumbers - The page numbers to view.IllegalArgumentException - Thrown when options is null.IllegalArgumentException - Thrown when pageNumbers is null or empty.PasswordRequiredException - Thrown when a password is required to open the document.IncorrectPasswordException - Thrown when the specified password is incorrect.GroupDocsViewerException - Thrown when the attachment could not be found.Copyright © 2025. All rights reserved.