Generate signature preview
GroupDocs.Signature provides PreviewSignatureOptions class to specify different options to manage signatures preview generation process.
Here are the steps to generate signature preview with GroupDocs.Signature:
- Instantiate the required SignOptions object with the settings you want to generate the preview
- Instantiate the PreviewSignatureOptions object with:
- delegate for signature stream creation (see event handler CreateSignatureStream);
- image preview format - PNG / JPG / BMP,
- unique signature identifier.
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 ReleaseSignatureStream to clean up resources.
- Call the static method GenerateSignaturePreviewmethod of Signature and pass PreviewSignatureOptions to it.
CreateSignatureStream delegate implementation
GroupDocs.Signature expects CreateSignatureStream delegate to obtain each signature stream for image preview generation process
private static CreateSignatureStream(PreviewSignatureOptions previewOptions)
{
SignOptions signOptions = previewOptions.SignOptions;
string imageFilePath = Path.Combine(Constants.OutputPath, "GenerateSignaturePreview", $"signature-{previewOptions.SignatureId}-{previewOptions.SignOptions.GetType().Name}.jpg");
var folder = Path.GetDirectoryName(imageFilePath);
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
return new FileStream(imageFilePath, FileMode.Create);
}
ReleaseSignatureStream delegate implementation
private static void ReleaseSignatureStream(PreviewSignatureOptions previewOptions, Stream signatureStream)
{
signatureStream.Dispose();
Console.WriteLine($"Signature {previewOptions.SignatureId}-{previewOptions.SignOptions.GetType().Name} is ready for preview");
}
Generate signature preview
public static void GetPreview()
{
// create options
QrCodeSignOptions signOptions = new QrCodeSignOptions
{
EncodeType = QrCodeTypes.QR,
// setup Data property with Address object
Data = new GroupDocs.Signature.Domain.Extensions.Address()
{
Street = "221B Baker Street",
City = "London",
State = "NW",
ZIP = "NW16XE",
Country = "England"
},
// set right bottom corner
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
Width = 100,
Height = 100,
Margin = new Padding(10)
};
// create signature preview options object
PreviewSignatureOptions previewOption = new PreviewSignatureOptions(signOptions, CreateSignatureStream, ReleaseSignatureStream)
{
SignatureId = Guid.NewGuid().ToString(),
PreviewFormat = PreviewSignatureOptions.PreviewFormats.JPEG,
};
// generate preview
Signature.GenerateSignaturePreview(previewOption);
}
private static Stream CreateSignatureStream(PreviewSignatureOptions previewOptions)
{
SignOptions signOptions = previewOptions.SignOptions;
string imageFilePath = $"signature-{previewOptions.SignatureId}-{previewOptions.SignOptions.GetType().Name}.jpg";
return new FileStream(imageFilePath, FileMode.Create);
}
private static void ReleaseSignatureStream(PreviewSignatureOptions previewOptions, Stream signatureStream)
{
signatureStream.Dispose();
Console.WriteLine($"Signature {previewOptions.SignatureId}-{previewOptions.SignOptions.GetType().Name} is ready for preview");
}
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:
- GroupDocs.Signature for .NET examples, plugins, and showcase
- GroupDocs.Signature for Java examples, plugins, and showcase
- Document Signature for .NET MVC UI Example
- Document Signature for .NET App WebForms UI Example
- Document Signature for Java App Dropwizard UI Example
- Document Signature for Java Spring UI Example
Free Online App
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.