Viewer
Leave feedback
On this page
Inheritance: java.lang.Object
All Implemented Interfaces: java.io.Closeable
public class Viewer implements Closeable
Represents the main class that controls the document rendering process.
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"));
}
| Field | Description |
|---|---|
| LOAD_OPTIONS | |
| SETTINGS | |
| FILE_READER | |
| OPTIONS |
| Method | Description |
|---|---|
| getViewInfo(ViewInfoOptions options) | Returns information about the view and document specific information. |
| getAttachments() | Returns attachments contained by the document. |
| saveAttachment(Attachment attachment, OutputStream destination) | Saves an attachment file to the destination stream. |
| view(ViewOptions options) | Creates a view of all document pages. |
| view(ViewOptions options, int[] pageNumbers) | Creates a view of specific document pages. |
| 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. |
| search(SearchHighlightOptions options) | Performs a text search and highlights matches (if found) in the loaded document according to the provided options. |
| getFileInfo() | Returns information about the file, such as file type and a flag that indicates if the file is encrypted. |
| close() | Releases the file stream and managed internal resources. |
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
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The method that returns a readable stream. |
public Viewer(InputStream fileStream, boolean leaveOpen)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The file stream. |
| leaveOpen | boolean | true to leave the stream open after the Viewer object is disposed; otherwise, false. |
public Viewer(InputStream fileStream, LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The readable stream. |
| loadOptions | LoadOptions | The document load options. |
public Viewer(InputStream fileStream, LoadOptions loadOptions, boolean leaveOpen)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The file stream. |
| loadOptions | LoadOptions | The document load options. |
| leaveOpen | boolean | 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 more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The file stream. |
| settings | ViewerSettings | The Viewer settings. |
public Viewer(InputStream fileStream, ViewerSettings settings, boolean leaveOpen)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The file stream. |
| settings | ViewerSettings | The Viewer settings. |
| leaveOpen | boolean | true to leave the stream open after the Viewer object is disposed; otherwise, false. |
public Viewer(InputStream fileStream, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The file stream. |
| loadOptions | LoadOptions | The document load options. |
| settings | ViewerSettings | The Viewer settings. |
public Viewer(InputStream fileStream, LoadOptions loadOptions, ViewerSettings settings, boolean leaveOpen)
Initializes new instance of Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileStream | java.io.InputStream | The file stream. |
| loadOptions | LoadOptions | The document load options. |
| settings | ViewerSettings | The Viewer settings. |
| leaveOpen | boolean | true to leave the stream open after the Viewer object is disposed; otherwise, false. |
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
Parameters:
| Parameter | Type | Description |
|---|---|---|
| url | java.net.URL | A URL to a file that should be loaded into the Viewer. |
public Viewer(URL url, LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| url | java.net.URL | A URL to a file that should be loaded into the Viewer. |
| loadOptions | LoadOptions | The document load options. |
public Viewer(URL url, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| url | java.net.URL | A URL to a file that should be loaded into the Viewer. |
| settings | ViewerSettings | The Viewer settings. |
public Viewer(URL url, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading encrypted documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| url | java.net.URL | A URL to a file that should be loaded into the Viewer. |
| loadOptions | LoadOptions | The document load options. |
| settings | ViewerSettings | The Viewer settings. |
public 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.
Learn more
- To learn about the file types supported by GroupDocs.Viewer, visit: Document formats supported by GroupDocs.Viewer
- To explore the features of GroupDocs.Viewer for Java, refer to: Developer Guide
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileReader | FileReader | The FileReader containing the document to be loaded into the Viewer. |
| settings | ViewerSettings | The ViewerSettings to be applied to the Viewer. |
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.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileReader | FileReader | The file reader. |
| loadOptions | LoadOptions | The load options. |
| settings | ViewerSettings | The Viewer settings. |
public Viewer(String filePath)
Initializes a new instance of the Viewer class.
Learn more:
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.lang.String | The path to the file to render. |
public Viewer(Path filePath)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.nio.file.Path | The path to the file to render. |
public Viewer(String filePath, LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading password-protected documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.lang.String | The path to the file to render. |
| loadOptions | LoadOptions | The document load options. |
public Viewer(Path filePath, LoadOptions loadOptions)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading password-protected documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view a document with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.nio.file.Path | The path to the file to render. |
| loadOptions | LoadOptions | The document load options. |
public Viewer(String filePath, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.lang.String | The path to the file to render. |
| settings | ViewerSettings | The Viewer settings. |
public Viewer(Path filePath, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.nio.file.Path | The path to the file to render. |
| settings | ViewerSettings | The Viewer settings. |
public Viewer(String filePath, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading password-protected documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view documents with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.lang.String | The path to the file to render. |
| loadOptions | LoadOptions | The document load options. |
| settings | ViewerSettings | The Viewer settings. |
public Viewer(Path filePath, LoadOptions loadOptions, ViewerSettings settings)
Initializes a new instance of the Viewer class.
Learn more
- More about file types supported by GroupDocs.Viewer: Document formats supported by GroupDocs.Viewer
- More about GroupDocs.Viewer for Java features: Developer Guide
- More about loading password-protected documents and viewing files from third-party storages with GroupDocs.Viewer for Java: How to load and view documents with GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| filePath | java.nio.file.Path | The path to the file to render. |
| loadOptions | LoadOptions | The document load options. |
| settings | ViewerSettings | The Viewer settings. |
public static final String LOAD_OPTIONS
public static final String SETTINGS
public static final String FILE_READER
public static final String OPTIONS
public final ViewInfo getViewInfo(ViewInfoOptions options)
Returns information about the view and document specific information.
Learn more:
- Learn more about the document - file type, page count, and other format specific properties: How to get file information using GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| options | ViewInfoOptions | The view info options. |
Returns: ViewInfo - Information about the view and document specific information.
public final List<Attachment> getAttachments()
Returns attachments contained by the document.
Learn more:
- Learn more about getting document attachments in Java: How to get a list of document attachments using GroupDocs.Viewer
- Learn more about saving document attachments in Java: How to save document attachments using GroupDocs.Viewer
Returns: java.util.List<com.groupdocs.viewer.results.Attachment> - attachments contained by the document.
public void saveAttachment(Attachment attachment, OutputStream destination)
Saves an attachment file to the destination stream.
Learn more:
- Learn more about getting document attachments in Java: How to get a list of document attachments using GroupDocs.Viewer
- Learn more about saving document attachments in Java: How to save document attachments using GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| attachment | Attachment | The attachment. |
| destination | java.io.OutputStream | The writable stream. |
public final void view(ViewOptions options)
Creates a view of all document pages.
Learn more
- Learn more about different viewing options following this guide: How to customize document viewing output using GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| options | ViewOptions | The view options. |
public final void view(ViewOptions options, int[] pageNumbers)
Creates a view of specific document pages.
Learn more
- Learn more about different viewing options following this guide: How to customize document viewing output using GroupDocs.Viewer
Parameters:
| Parameter | Type | Description |
|---|---|---|
| options | ViewOptions | The view options. |
| pageNumbers | int[] | The page numbers to view. |
public 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.
For details, see the documentation.
Returns: com.groupdocs.viewer.fonts.IFontInfo[] - Non-null list of all fonts used in the document loaded into this Viewer instance.
public void search(SearchHighlightOptions options)
Performs a text search and highlights matches (if found) in the loaded document according to the provided options.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| options | com.groupdocs.viewer.options.SearchHighlightOptions | Search and highlight options, including a text phrase to search. Cannot be null . |
public FileInfo getFileInfo()
Returns information about the file, such as file type and a flag that indicates if the file is encrypted.
Learn more:
- Learn more about how to check if a file is encrypted: How to check if a file is encrypted
Returns: FileInfo - the file information.
public final void close()
Releases the file stream and managed internal resources.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.