GroupDocs.Comparison allows you to generate page previews for source, target and output document(s) using the generatePreview() method of the Document class.
Use the PreviewOptions class to manage the preview generation process - specify desired page numbers, image format, etc.
To generate the document preview using the GroupDocs.Comparison API, follow these steps:
Create an instance of the Comparer class. Specify the source document path as a constructor parameter.
Add the target document to comparison using the add() method.
The getSource() and getTargets() methods of the Comparer object allow you to access source and target documents and the generatePreview() method.
Instantiate the PreviewOptions object. Specify the following parameters:
delegate for each page stream creation (see the reatePageStreamFunction event handler)
image preview format - PNG / JPG / BMP
page numbers to process
custom size of preview images (if needed)
Note
Stream created by the CreatePageStreamFunction delegate is automatically disposed when the preview image is generated. If you need to implement the custom disposing of the image preview stream, specify the ReleasePageStreamFunction argument to clean up resources.
Call the generatePreview() method of the Source and Targets documents. Specify the PreviewOptions.
The PreviewOptions class’s main methods are as follows:
getCreatePageStreamFunction() returns a delegate that defines a method to create the output page preview stream
getReleasePageStreamFunction() returns a delegate that defines a method to remove the output page preview stream. This can be used when you need advanced control of resource handling
setWidth sets the preview image width. Use this method to customize the output image width
setHeight sets the preview image height. Use this method to customize output image height
setPageNumbers defines an array of page numbers to be previewed;
setPreviewFormat sets the preview image format which provides an ability to choose between image quality and size. Use the BMP format for the best image quality. Use the JPG format to produce the smallest image size (and faster loading image previews) but with lower quality than BMP. By default, GroupDocs.Comparison uses the PNG format to provide appropriate image quality and size.
The following code snippet shows how to generate document previews:
This feature is not supported for WordProcessing documents.
Get page previews and clean resources manually
constcomparer=newgroupdocs.comparison.Comparer(sourceFile);comparer.add(targetFile);constresultPath=comparer.compare(outputFile);constdocument=newgroupdocs.comparison.Document(resultPath);constpreviewOptions=newgroupdocs.comparison.PreviewOptions(pageNumber=>Files.newOutputStream(previewDirectory+"result-GetPagePreviewsResouresCleaning_"+pageNumber+".png"));previewOptions.setPreviewFormat(groupdocs.comparison.PreviewFormats.PNG);previewOptions.setPageNumbers(newint[]{1,2});previewOptions.setReleasePageStreamFunction(newgroupdocs.comparison.ReleasePageStreamFunction(){@Overridepublicvoidinvoke(intpageNumber,OutputStreamoutputStream){System.out.println("Releasing memory for page: "+pageNumber);outputStream.close();}});document.generatePreview(previewOptions);
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.