Guide to Signing Images with Metadata Using GroupDocs.Signature
Introduction
GroupDocs.Signature for .NET is a powerful library that allows developers to efficiently sign images with metadata. This tutorial will guide you through the process step by step.
Prerequisites
Before you start, ensure you have the following:
- GroupDocs.Signature for .NET: Install the GroupDocs.Signature package in your .NET project. You can download it from here.
- Image File: Prepare the image file you want to sign with metadata.
Import Necessary Namespaces
In your C# code, import the following namespaces:
using System;
using System.IO;
using GroupDocs.Signature;
using GroupDocs.Signature.Domain;
using GroupDocs.Signature.Options;
Step 1: Load Your Image File
Begin by specifying the path to your image file and the output directory for the signed image:
string filePath = "sample.png";
string outputFilePath = Path.Combine("Your Document Directory", "SignImageWithMetadata", "SignedWithMetadata.png");
Step 2: Create Metadata Signatures
Next, create metadata signatures and add them to the signing options:
using (Signature signature = new Signature(filePath))
{
ushort imgsMetadataId = 41996; // Starting ID for metadata
MetadataSignOptions options = new MetadataSignOptions();
// Add various types of metadata signatures
options
.Add(new ImageMetadataSignature(imgsMetadataId++, "Mr. Sherlock Holmes")) // String value
.Add(new ImageMetadataSignature(imgsMetadataId++, DateTime.Now)) // DateTime value
.Add(new ImageMetadataSignature(imgsMetadataId++, 123456)) // Integer value
.Add(new ImageMetadataSignature(imgsMetadataId++, 123.456D)) // Double value
.Add(new ImageMetadataSignature(imgsMetadataId++, 123.456M)) // Decimal value
.Add(new ImageMetadataSignature(imgsMetadataId++, 123.456F)); // Float value
// Sign the document and save the result
SignResult result = signature.Sign(outputFilePath, options);
Console.WriteLine($"\nDocument signed successfully with {result.Succeeded.Count} signature(s).\nFile saved at: {outputFilePath}");
}
Conclusion
In this tutorial, you learned how to sign an image with metadata using GroupDocs.Signature for .NET. By following these steps, you can easily add metadata signatures to your .NET applications, enhancing the functionality and integrity of your images.
FAQ’s
Can I sign multiple images with metadata using GroupDocs.Signature for .NET?
Yes, you can sign multiple images by iterating through each image file and applying the metadata signatures.
Is there a trial version available for GroupDocs.Signature for .NET?
Yes, you can download the trial version from here.
Does GroupDocs.Signature for .NET support other file formats besides images?
Absolutely! GroupDocs.Signature supports various formats, including PDF, Word, Excel, and more.
Can I customize the appearance of the metadata signature?
Yes, you can customize aspects like font size, color, and position of the metadata signature.
Where can I get support for GroupDocs.Signature for .NET?
For support, visit the GroupDocs.Signature forum here.