GroupDocs.Signature provides PreviewOptions class to specify different options to manage document pages preview generation process. Since 20.3 version there’s ability to hide signatures from documents. Using property setHideSignature of PreviewOptions will allow to hide signatures from document preview.
Here are the steps to generate document preview with GroupDocs.Signature with hidden signatures:
Create new instance of Signature class and pass source document path as a constructor parameter.
Stream 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 closePageStream to clean up resources.
Generate document preview without signatures on it
publicstaticvoidgetPreview(){// The path to the documents directory.
StringfilePath="C:\signed.pdf";Signaturesignature=newSignature(filePath);try{// create preview options object
PreviewOptionspreviewOption=newPreviewOptions(newPageStreamFactory(){@OverridepublicOutputStreamcreatePageStream(intpageNumber){returngenerateStream(pageNumber);}@OverridepublicvoidclosePageStream(intpageNumber,OutputStreampageStream){releasePageStream(pageNumber,pageStream);}});previewOption.setPreviewFormat(PreviewFormats.JPEG);previewOption.setHideSignatures(true);// generate preview
signature.generatePreview(previewOption);}catch(Exceptione){thrownewGroupDocsSignatureException(e.getMessage());}}privatestaticOutputStreamgenerateStream(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());}}privatestaticvoidreleasePageStream(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());}}
More resources
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.