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.
This example demonstrates how to generate a preview image for a QR Code signature using GroupDocs.Signature with default sizes.
publicstaticvoidGetPreview(){// Create QR code sign optionsQrCodeSignOptionssignOptions=newQrCodeSignOptions{EncodeType=QrCodeTypes.QR,Data=newGroupDocs.Signature.Domain.Extensions.Address{Street="221B Baker Street",City="London",State="NW",ZIP="NW16XE",Country="England"},HorizontalAlignment=HorizontalAlignment.Left,VerticalAlignment=VerticalAlignment.Center,Margin=newPadding(10)};// Create signature preview optionsPreviewSignatureOptionspreviewOption=newPreviewSignatureOptions(signOptions,CreateSignatureStream,ReleaseSignatureStream){SignatureId=Guid.NewGuid().ToString(),PreviewFormat=PreviewSignatureOptions.PreviewFormats.JPEG};// Generate signature previewSignature.GenerateSignaturePreview(previewOption);}privatestaticStreamCreateSignatureStream(PreviewSignatureOptionspreviewOptions){stringimageFilePath=$"signature-{previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name}.jpg";returnnewFileStream(imageFilePath,FileMode.Create);}privatestaticvoidReleaseSignatureStream(PreviewSignatureOptionspreviewOptions,StreamsignatureStream){signatureStream.Dispose();Console.WriteLine($"Signature {previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name} is ready for preview");}
Adaptive rendering for QR Code signature previews
Note
If the specified width and height are not appropriate for generating a readable QR Code preview, the system will automatically use default size values. These defaults are chosen as the nearest optimal dimensions to ensure the QR Code remains clear and scannable.
This example demonstrates how to generate a preview image for a QR Code signature using GroupDocs.Signature. You’ll see how to configure the QR Code’s appearance, including size, color, and text alignment, and how to generate and save the preview image stream.
publicstaticvoidGetPreview(){// Initialize QR Code signing optionsQrCodeSignOptionsqrSignOptions=newQrCodeSignOptions("GROUP DOCS",QrCodeTypes.QR){Width=250,// Width of the QR codeHeight=270,// Height of the QR codeForeColor=Color.Red,// Color of the QR codeCodeTextAlignment=CodeTextAlignment.Below,// Text alignment relative to the QR codeText="GROUP DOCS"// Text displayed below the QR code};// Configure preview generation options for the QR code signaturePreviewSignatureOptionspreviewOptions=newPreviewSignatureOptions(qrSignOptions,CreateSignatureStream,// Delegate to create the streamReleaseSignatureStream// Delegate to release the stream){SignatureId=Guid.NewGuid().ToString(),// Unique identifier for the previewPreviewFormat=PreviewSignatureOptions.PreviewFormats.PNG// Output format of preview};// Generate the signature preview imageSignature.GenerateSignaturePreview(previewOptions);}privatestaticStreamCreateSignatureStream(PreviewSignatureOptionspreviewOptions){stringimageFilePath=$"signature-{previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name}.jpg";returnnewFileStream(imageFilePath,FileMode.Create);}privatestaticvoidReleaseSignatureStream(PreviewSignatureOptionspreviewOptions,StreamsignatureStream){signatureStream.Dispose();Console.WriteLine($"Signature {previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name} is ready for preview");}
Adaptive rendering for Barcode signature previews
Note
When the width and height provided for the Barcode preview are not suitable, the preview generation will fall back to default size values. These defaults are selected to produce a barcode image that is readable and properly rendered.
This section shows how to create a preview for a Barcode signature. The example covers setting barcode properties such as type, size, and color, as well as generating the preview image with a custom stream handler.
publicstaticvoidGetPreview(){// Initialize QR Code signing optionsBarcodeSignOptionssignOptions=newBarcodeSignOptions("GROUP DOCS",BarcodeTypes.MaxiCode){Width=400,// Width of the Barcode codeHeight=400,// Height of the Barcode codeForeColor=Color.Red,// Color of the Barcode codeCodeTextAlignment=CodeTextAlignment.Below,// Text alignment relative to the Barcode codeText="GROUP DOCS"// Text displayed below the Barcode code};// Configure preview generation options for the QR code signaturePreviewSignatureOptionspreviewOptions=newPreviewSignatureOptions(qrSignOptions,CreateSignatureStream,// Delegate to create the streamReleaseSignatureStream// Delegate to release the stream){SignatureId=Guid.NewGuid().ToString(),// Unique identifier for the previewPreviewFormat=PreviewSignatureOptions.PreviewFormats.PNG// Output format of preview};// Generate the signature preview imageSignature.GenerateSignaturePreview(previewOptions);}privatestaticStreamCreateSignatureStream(PreviewSignatureOptionspreviewOptions){stringimageFilePath=$"signature-{previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name}.jpg";returnnewFileStream(imageFilePath,FileMode.Create);}privatestaticvoidReleaseSignatureStream(PreviewSignatureOptionspreviewOptions,StreamsignatureStream){signatureStream.Dispose();Console.WriteLine($"Signature {previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name} is ready for preview");}
Rotate Barcode and QR Code previews
This example demonstrates how to apply rotation to Barcode and QR Code signature previews. Rotation can help fit signatures into specific layout requirements or create visual effects.
publicstaticvoidGetPreview(){// Initialize Barcode signing optionsBarcodeSignOptionsbarcodeSignOptions=newBarcodeSignOptions("GROUP DOCS",BarcodeTypes.MaxiCode){Width=400,// Width of the barcodeHeight=400,// Height of the barcodeForeColor=Color.Red,// Foreground color of the barcodeCodeTextAlignment=CodeTextAlignment.Below,// Position of the text relative to the barcodeText="GROUP DOCS",// Text displayed with the barcodeRotationAngle=45// Rotate the barcode by 45 degrees};// Configure preview generation options for the QR code signaturePreviewSignatureOptionspreviewOptions=newPreviewSignatureOptions(qrSignOptions,CreateSignatureStream,// Delegate to create the streamReleaseSignatureStream// Delegate to release the stream){SignatureId=Guid.NewGuid().ToString(),// Unique identifier for the previewPreviewFormat=PreviewSignatureOptions.PreviewFormats.PNG// Output format of preview};// Generate the signature preview imageSignature.GenerateSignaturePreview(previewOptions);}privatestaticStreamCreateSignatureStream(PreviewSignatureOptionspreviewOptions){stringimageFilePath=$"signature-{previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name}.jpg";returnnewFileStream(imageFilePath,FileMode.Create);}privatestaticvoidReleaseSignatureStream(PreviewSignatureOptionspreviewOptions,StreamsignatureStream){signatureStream.Dispose();Console.WriteLine($"Signature {previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name} is ready for preview");}
Transparency for Barcode/QR previews
This snippet shows how to set the transparency level of Barcode or QR Code previews, allowing you to customize the signature’s visual blending with the underlying document.
publicstaticvoidGetPreview(){// Initialize barcode signing options with Codabar typeBarcodeSignOptionsbarcodeSignOptions=newBarcodeSignOptions("GROUP DOCS",BarcodeTypes.Codabar){Width=400,// Width of the barcode previewHeight=400,// Height of the barcode previewForeColor=Color.Red,// Foreground color of the barcode barsCodeTextAlignment=CodeTextAlignment.Below,// Position text below the barcodeText="GROUP DOCS",// Text displayed with the barcodeTransparency=0.5// Set barcode background transparency (50%)};// Configure preview generation options for the QR code signaturePreviewSignatureOptionspreviewOptions=newPreviewSignatureOptions(qrSignOptions,CreateSignatureStream,// Delegate to create the streamReleaseSignatureStream// Delegate to release the stream){SignatureId=Guid.NewGuid().ToString(),// Unique identifier for the previewPreviewFormat=PreviewSignatureOptions.PreviewFormats.PNG// Output format of preview};// Generate the signature preview imageSignature.GenerateSignaturePreview(previewOptions);}privatestaticStreamCreateSignatureStream(PreviewSignatureOptionspreviewOptions){stringimageFilePath=$"signature-{previewOptions.SignatureId}-"+$"{previewOptions.SignOptions.GetType().Name}.jpg";returnnewFileStream(imageFilePath,FileMode.Create);}privatestaticvoidReleaseSignatureStream(PreviewSignatureOptionspreviewOptions,StreamsignatureStream){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: