Generate document pages preview
GroupDocs.Annotation allows to generate document page previews using generatePreview method of a Document class.
PreviewOptions class is used to manage preview generation process - specify desired page numbers, image format etc.
Here are the steps to generate document preview with GroupDocs.Annotation API:
- Create new instance of Annotator class and pass source document path as a constructor parameter.
- Document field of Annotator object allows to access source document and provides generatePreview method.
- Instantiate the PreviewOptions object with path format to generated images;
- Specify image preview format - PNG / JPG / BMP via setPreviewFormat method;
- page numbers to process via setPageNumbers method;
- Call generatePreview method of Annotator.getDocument() method result and pass PreviewOptions to it.
GroupDocs.Annotation provides an ability to choose between image quality and size. BMP format should be used for the best image quality. JPG format will be useful in case of strict requirements to image size - it produces smallest image size (and faster loading image previews), but with lower quality than BMP. By default PNG format is selected - which is a golden mean between image quality and size.
The following code snippet demonstrates how to generate document previews.
Get document page previews
Annotator annotator = new Annotator("input.pdf");
PreviewOptions previewOptions = new PreviewOptions("C://Output//GenerateDocumentPagesPreview_{0}.png");
previewOptions.setPreviewFormat(PreviewFormats.PNG);
previewOptions.setPageNumbers(new int[]{1, 2});
annotator.getDocument().generatePreview(previewOptions);
annotator.dispose();
More resources
Advanced Usage Topics
To learn more about document annotating features, please refer to the advanced usage section.
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Annotation for .NET examples, plugins, and showcase
- GroupDocs.Annotation for Java examples, plugins, and showcase
- Document Annotation for .NET MVC UI Example
- Document Annotation for .NET App WebForms UI Modern Example
- Document Annotation for Java App Dropwizard UI Modern Example
- Document Annotation for Java Spring UI Example
Free Online App
Along with full-featured Java library we provide simple, but powerful free Apps.
You are welcome to annotate your PDF, DOC or DOCX, XLS or XLSX, PPT or PPTX, PNG and other documents with free to use online GroupDocs Annotation App.