GroupDocs.Watermark can generate a preview image for every page of a document. Use previews to show the pages to a user, for example to check a watermark before or after you save the document.
Generate document preview
To create document preview:
Create an instance of the Watermarker class for a local file or file stream;
Instantiate the PreviewOptions object with an implementation of the ICreatePageStream interface. It returns the output stream for each page image.
If you need to close the page streams yourself, also pass an implementation of the IReleasePageStream interface.
Specify the preview format - PreviewOptions.PreviewFormats.PNG, JPEG, or BMP - and other options like the page numbers for which you want to generate the preview. For most document types, you can also use a format-specific subclass of PreviewOptions, like PdfPreviewOptions or SpreadsheetPreviewOptions, which allows you to set the resolution of the generated images in dots per inch.
Call the generatePreview method of the Watermarker object and pass PreviewOptions to it.
ICreatePageStream and IReleasePageStream have a single method each, so you can implement them with lambda expressions:
Run the program. It will create images in the outputDirectory folder corresponding to the pages of the document.
The GroupDocs.Watermark for Java examples repository contains a runnable preview example, basic_usage.GenerateDocumentPreview, that implements the interfaces with classes.
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.
On this page
Ask AI
Ask anything about this page — the answer is based on its content.
Searching the docs and writing an answer…
Something went wrong while getting an answer. Please try again in a moment.