Stream that were created by createSignatureStream 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 closeSignatureStream to clean up resources.
privatestaticvoidreleaseSignatureStream(PreviewSignatureOptionspreviewOptions,OutputStreamsignatureStream){try{signatureStream.close();StringimageFilePath=newFile("C:\\Output\\GenerateSignaturePreviewAdvanced\\\\signature"+previewOptions.getSignatureId()+"-"+previewOptions.getSignOptions().getSignatureType()+".jpg").getPath();System.out.print("Image file "+imageFilePath+" is ready for preview");}catch(Exceptione){thrownewRuntimeException(e.getMessage());}}
Generate signature preview
publicstaticvoidGetPreview(){// create options
QrCodeSignOptionssignOptions=newQrCodeSignOptions();{signOptions.setEncodeType(QrCodeTypes.QR);// setup Data property with Address object
Addressaddress=newAddress();address.setStreet("221B Baker Street");address.setCity("London");address.setState("NW");address.setZIP("NW16XE");address.setCountry("England");signOptions.setData(address);// set right bottom corner
signOptions.setHorizontalAlignment(HorizontalAlignment.Left);signOptions.setVerticalAlignment(VerticalAlignment.Center);signOptions.setWidth(100);signOptions.setHeight(100);signOptions.setMargin(newPadding(10));};// create signature preview options object
PreviewSignatureOptionspreviewOption=newPreviewSignatureOptions(signOptions,newPageSignatureStreamFactory(){@OverridepublicOutputStreamcreateSignatureStream(PreviewSignatureOptionspreviewOptions){returngenerateSignatureStream(previewOptions);}@OverridepublicvoidcloseSignatureStream(PreviewSignatureOptionspreviewOptions,OutputStreampageStream){releaseSignatureStream(previewOptions,pageStream);}});previewOption.setSignatureId(UUID.randomUUID().toString());previewOption.setPreviewFormat(PreviewFormats.JPEG);// generate preview
Signature.generateSignaturePreview(previewOption);}privatestaticOutputStreamgenerateSignatureStream(PreviewSignatureOptionspreviewOptions){try{Pathpath=Paths.get(Constants.OutputPath,"\\GenerateSignaturePreviewAdvanced\\");if(!Files.exists(path)){Files.createDirectory(path);System.out.println("Directory created");}else{System.out.println("Directory already exists");}FileimageFilePath=newFile(path+"\\signature"+previewOptions.getSignatureId()+"-"+previewOptions.getSignOptions().getSignatureType()+".jpg");returnnewFileOutputStream(imageFilePath);}catch(Exceptione){thrownewRuntimeException(e.getMessage());}}privatestaticvoidreleaseSignatureStream(PreviewSignatureOptionspreviewOptions,OutputStreamsignatureStream){try{signatureStream.close();StringimageFilePath=newFile(Constants.OutputPath+"\\GeneratePreviewHideSignatures\\signature"+previewOptions.getSignatureId()+"-"+previewOptions.getSignOptions().getSignatureType()+".jpg").getPath();System.out.print("Image file "+imageFilePath+" is ready for preview");}catch(Exceptione){thrownewRuntimeException(e.getMessage());}}
Advanced Usage Topics
To learn more about document eSign features, please refer to the advanced usage section.
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: