delegate for each page output stream creation (see event handler CreatePageStream);
image preview format - PNG / JPG / BMP;
page numbers to process;
custom size of preview images (if needed).
Note
OutputStream that were created by CreatePageStream delegate will be disposed automatically once after generation of preview image. If you need to implement custom image preview stream disposing you have to pass additional argument ReleasePageStream to clean up resources.
privatestaticvoidreleasePageStream(intpageNumber,OutputStreampageStream){try{pageStream.close();StringimageFilePath=newFile("GeneratePreviewFolder","image-"+pageNumber+".jpg").getPath();System.out.print("Image file "+imageFilePath+" is ready for preview.");}catch(Exceptione){thrownewGroupDocsException(e.getMessage());}}
Generate document preview from stream with custom stream releasing delegate
publicstaticvoidgetPreview(){stringfilePath="c:\sample.xlsx";Mergermerger=newMerger(filePath);IPreviewOptionspreviewOption=newPreviewOptions(newCreatePageStream(){@OverridepublicOutputStreaminvoke(intpageNumber){returncreatePageStream(pageNumber);}},newReleasePageStream(){@Overridepublicvoidinvoke(intpageNumber,OutputStreampageStream){releasePageStream(pageNumber,pageStream);}},PreviewMode.JPEG);merger.generatePreview(previewOption);}privatestaticOutputStreamcreatePageStream(intpageNumber){try{StringimageFilePath=newFile("GeneratePreviewFolder","image-"+pageNumber+".jpg").getPath();returnnewFileOutputStream(imageFilePath);}catch(Exceptione){thrownewGroupDocsException(e.getMessage());}}privatestaticvoidreleasePageStream(intpageNumber,OutputStreampageStream){try{pageStream.close();StringimageFilePath=newFile("GeneratePreviewFolder","image-"+pageNumber+".jpg").getPath();System.out.print("Image file "+imageFilePath+" is ready for preview.");}catch(Exceptione){thrownewGroupDocsException(e.getMessage());}}privatestaticStringgetImagePath(intpageNumber){returnConstants.OutputPath+"GeneratePreview\\image-"+pageNumber+".jpg";}
Note
NOTE: Stream that was created over CreatePageStream delegate will be disposed automatically once after generation of preview image. If you need to implement custom image preview stream disposing you have to pass additional argument ReleasePageStreamto clean up 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.