Stream created by the CreatePageStreamFunction delegate is disposed automatically when 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.
getReleasePageStreamFunction() returns a delegate which defines method to remove output page preview stream. This is can be used when need advanced control for resources handling
setWidth sets the preview image width. Use this method to customize 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 ability to choose between image quality and size. Use the BMP format for the best image quality. Use the JPG format to produce 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
try(Comparercomparer=newComparer(sourceFile)){comparer.add(targetFile);finalPathresultPath=comparer.compare(outputFile);Documentdocument=newDocument(resultPath);PreviewOptionspreviewOptions=newPreviewOptions(newCreatePageStreamFunction(){@OverridepublicOutputStreaminvoke(intpageNumber){returnnewFileOutputStream(previewDirectory+"result-GetPagePreviewsResouresCleaning_"+pageNumber+".png");}});previewOptions.setPreviewFormat(PreviewFormats.PNG);previewOptions.setPageNumbers(newint[]{1,2});previewOptions.setReleasePageStreamFunction(newReleasePageStreamFunction(){@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.