Important note! Stream that were created by createPageStream method 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 method closePageStream to clean up resources.
Generate document preview from file on local disk
// instantiating the signature object
finalSignaturesignature=newSignature("sample.pdf");PreviewOptionspreviewOption=newPreviewOptions("C:\\GeneratePreviewHideSignatures\\image.jpg",0);previewOptions.setPreviewFormat(PreviewFormats.PNG);signature.generatePreview(previewOptions);
createPageStream method implementation
GroupDocs.Signature expects createPageStream method to obtain each page stream for image preview generation process
@OverridepublicvoidclosePageStream(intpageNumber,OutputStreampageStream){try{pageStream.close();StringimageFilePath=newFile("GeneratePreviewFolder","image-"+pageNumber+".jpg").getPath();System.out.print("Image file "+imageFilePath+" is ready for preview");}catch(Exceptione){thrownewGroupDocsSignatureException(e.getMessage());}}
Generate document preview from stream with custom stream creating and closing methods
// instantiating the signature object
FileInputStreamstream=newFileInputStream("sample.pdf")finalSignaturesignature=newSignature(stream);// Image from specified page
PreviewOptionspreviewOption=newPreviewOptions(newPageStreamFactory(){@OverridepublicOutputStreamcreatePageStream(intpageNumber){try{Pathpath=Paths.get("C:\\GeneratePreviewHideSignatures");if(!Files.exists(path)){Files.createDirectory(path);System.out.println("Directory created");}else{System.out.println("Directory already exists");}FilefilePath=newFile(path+"\\image-"+pageNumber+".jpg");returnnewFileOutputStream(filePath);}catch(Exceptione){thrownewGroupDocsSignatureException(e.getMessage());}}@OverridepublicvoidclosePageStream(intpageNumber,OutputStreampageStream){try{pageStream.close();StringimageFilePath=newFile("C:\\GeneratePreviewHideSignatures","image-"+pageNumber+".jpg").getPath();System.out.print("Image file "+imageFilePath+" is ready for preview");}catch(Exceptione){thrownewGroupDocsSignatureException(e.getMessage());}}});previewOptions.setPreviewFormat(PreviewFormats.PNG);signature.generatePreview(previewOptions);
More resources
Advanced Usage Topics
To learn more about document eSign 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:
Along with full-featured .NET library we provide simple, but powerful free Apps. You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.
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.