/// <summary> /// Sign pdf document with metadata signature /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Basic Usage] # SignPdfWithMetadata : Sign pdf document with metadata signature\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_PDF; string outputFilePath = Path.Combine(Constants.OutputPath, "SignPdfWithMetadata", "SignedWithMetadata.pdf"); // create Signature instance using (Signature signature = new Signature(filePath)) { // create Metadata option with predefined Metadata text MetadataSignOptions options = new MetadataSignOptions(); // Create few Pdf Metadata signatures PdfMetadataSignature[] signatures = new PdfMetadataSignature[] { new PdfMetadataSignature("Author", "Mr.Scherlock Holmes"), // String value new PdfMetadataSignature("CreatedOn", DateTime.Now), // DateTime values new PdfMetadataSignature("DocumentId", 123456), // Integer value new PdfMetadataSignature("SignatureId", 123.456D), // Double value new PdfMetadataSignature("Amount", 123.456M), // Decimal value new PdfMetadataSignature("Total", 123.456F) // Float value }; options.Signatures.AddRange(signatures); // sign document to file SignResult result = signature.Sign(outputFilePath, options); Console.WriteLine($"\nSource document signed successfully with {result.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}."); } }
/// <summary> /// Sign pdf document with metadata signature with customer object and encryption /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # SignPdfWithCustomMetadata : Sign pdf document with metadata signature with customer object and encryption\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_PDF; string fileName = Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "SignPdfWithCustomMetadata", fileName); using (Signature signature = new Signature(filePath)) { // setup key and passphrase string key = "1234567890"; string salt = "1234567890"; // create data encryption IDataEncryption encryption = new SymmetricEncryption(SymmetricAlgorithmType.Rijndael, key, salt); // setup options with text of signature MetadataSignOptions options = new MetadataSignOptions(); // create custom object DocumentSignatureData documentSignature = new DocumentSignatureData() { ID = Guid.NewGuid().ToString(), Author = Environment.UserName, Signed = DateTime.Now, DataFactor = 11.22M }; // Specify different Metadata Signatures and add them to options signature collection // setup Author property PdfMetadataSignature mdDocument = new PdfMetadataSignature("DocumentSignature", documentSignature); // set encryption mdDocument.DataEncryption = encryption; // setup Author property PdfMetadataSignature mdAuthor = new PdfMetadataSignature("Author", "Mr.Scherlock Holmes"); // set encryption mdAuthor.DataEncryption = encryption; // setup data of document id PdfMetadataSignature mdDocId = new PdfMetadataSignature("DocumentId", Guid.NewGuid().ToString()); // set encryption mdDocId.DataEncryption = encryption; // add signatures to options options.Signatures.Add(mdDocument); options.Signatures.Add(mdAuthor); options.Signatures.Add(mdDocId); // sign document to file SignResult signResult = signature.Sign(outputFilePath, options); Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}."); } }