Generate signature preview

GroupDocs.Signature PreviewSignatureOptionsΒ classΒ to specify different options to manage signatures preview generation process.

Here are the steps how 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.
Note
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.

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:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.