static BarcodeSignOptions GetBarcodeSignOptions() { BarcodeSignOptions result = new BarcodeSignOptions("123456789012", BarcodeTypes.Code39Standard); // alignment settings result.Left = 100; result.Top = 50; result.Width = 200; result.Height = 120; result.AllPages = true; result.PageNumber = 1; result.PagesSetup = new PagesSetup() { FirstPage = true, LastPage = false, OddPages = true, EvenPages = false, PageNumbers = { 1, 2, 3 } }; result.HorizontalAlignment = Domain.HorizontalAlignment.Right; result.VerticalAlignment = Domain.VerticalAlignment.Top; // border settings result.Border.Color = System.Drawing.Color.Red; result.Border.DashStyle = GroupDocs.Signature.Domain.DashStyle.DashLongDash; result.Border.Transparency = 0.8; result.Border.Weight = 2; result.Border.Visible = true; // background settings result.Background.Color = System.Drawing.Color.Yellow; result.Background.Transparency = 0.5; result.ForeColor = System.Drawing.Color.Green; return(result); }
/// <summary> /// Sign document with barcode signature /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Basic Usage] # SignWithBarcode : Sign document with Barcode\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_PDF; string fileName = Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithBarcode", fileName); using (Signature signature = new Signature(filePath)) { // create barcode option with predefined barcode text BarcodeSignOptions options = new BarcodeSignOptions("JohnSmith") { // setup Barcode encoding type EncodeType = BarcodeTypes.Code128, // set signature position Left = 50, Top = 150, Width = 200, Height = 50 }; // 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> /// Add signature data for word document /// </summary> /// <returns>SignOptions</returns> public override SignOptions SignWord() { // setup options BarcodeSignOptions signOptions = new BarcodeSignOptions(QrCodeData.text); SetOptions(signOptions); return(signOptions); }
private BarcodeSignOptions GetBarcodeSignOptions(string signText, string signLocation, string signSize) { var options = new BarcodeSignOptions(signText) { EncodeType = BarcodeTypes.Code128, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Padding(10), Border = new Border() { Color = Color.LightGray, DashStyle = DashStyle.Solid, Transparency = 0.5, Visible = true, Weight = 2 }, ForeColor = Color.Black, Font = new SignatureFont { Size = 12, FamilyName = "Comic Sans MS" }, CodeTextAlignment = CodeTextAlignment.Below, Background = new Background() { Color = Color.LightSteelBlue, Transparency = 0.2, Brush = new LinearGradientBrush(Color.White, Color.LightSteelBlue) } }; QrCodeSignOptions locationOptions = GetLocationOptions(signLocation); options.HorizontalAlignment = locationOptions.HorizontalAlignment; options.VerticalAlignment = locationOptions.VerticalAlignment; switch (signSize) { case "small": options.Width = 100; options.Height = 50; break; case "medium": options.Width = 100 * 2; options.Height = 50 * 2; break; case "large": options.Width = 100 * 3; options.Height = 50 * 3; break; } return(options); }
public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Quick Start] # Options serialization and deserialization\n"); List <SignOptions> collection = new List <SignOptions>(); TextSignOptions textSignOptions = GetTextSignOptions(); collection.Add(textSignOptions); ImageSignOptions imageSignOptions = GetImageSignOptions(); collection.Add(imageSignOptions); DigitalSignOptions digitalSignOptions = GetDigitalSignOptions(); collection.Add(digitalSignOptions); BarcodeSignOptions barcodeSignOptions = GetBarcodeSignOptions(); collection.Add(barcodeSignOptions); QrCodeSignOptions qrCodeSignOptions = GetQrCodeSignOptions(); collection.Add(qrCodeSignOptions); string serialized = JsonConvert.SerializeObject(collection); JsonConverter[] converters = { new SignOptionsJsonConverter(), new BarcodeTypeJsonConverter(), new QrCodeTypeJsonConverter() }; List <SignOptions> deserialized = JsonConvert.DeserializeObject <List <SignOptions> >(serialized, converters); Console.WriteLine(deserialized.Count); if (deserialized != null) { // The path to the documents directory. string filePath = Constants.SAMPLE_PDF; string fileName = System.IO.Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "OptionsSerialization", fileName); using (Signature signature = new Signature(filePath)) { // sign document to file SignResult signResult = signature.Sign(outputFilePath, deserialized); Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}."); } } }
/// <summary> /// Sign document with text signature applying specific options /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # SignWithStretchMode : Sign document with text signature applying specific options\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_WORDPROCESSING; string fileName = Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithStretch", fileName); using (Signature signature = new Signature(filePath)) { // define several signature options of different types and settings TextSignOptions textOptions = new TextSignOptions("This is test message") { AllPages = true, VerticalAlignment = VerticalAlignment.Top, Margin = new Padding(50), Stretch = StretchMode.PageWidth }; BarcodeSignOptions barcodeOptions = new BarcodeSignOptions("123456") { AllPages = true, EncodeType = BarcodeTypes.Code128, VerticalAlignment = VerticalAlignment.Bottom, Margin = new Padding(50), Stretch = StretchMode.PageWidth }; ImageSignOptions imageOptions = new ImageSignOptions() { AllPages = true, Stretch = StretchMode.PageHeight, HorizontalAlignment = HorizontalAlignment.Right, ImageFilePath = Constants.ImageHandwrite }; // define list of signature options List <SignOptions> listOptions = new List <SignOptions>(); listOptions.Add(textOptions); listOptions.Add(barcodeOptions); listOptions.Add(imageOptions); // sign document to file SignResult signResult = signature.Sign(outputFilePath, listOptions); Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}."); } }
private static void SetOptions(BarcodeSignOptions signOptions) { signOptions.EncodeType = BarcodeTypes.Code39Standard; signOptions.HorizontalAlignment = SignatureData.getHorizontalAlignment(); signOptions.VerticalAlignment = SignatureData.getVerticalAlignment(); signOptions.Width = Convert.ToInt32(SignatureData.ImageWidth); signOptions.Height = Convert.ToInt32(SignatureData.ImageHeight); signOptions.Top = Convert.ToInt32(SignatureData.Top); signOptions.Left = Convert.ToInt32(SignatureData.Left); signOptions.PageNumber = SignatureData.PageNumber; if (SignatureData.Angle != 0) { signOptions.RotationAngle = SignatureData.Angle; } }
/// <summary> /// Sign document with setting position of signature /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # SignWithMillimeters : Sign document with setting position of signature\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_PDF; string fileName = Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithMillimeters", fileName); using (Signature signature = new Signature(filePath)) { // create barcode option with predefined barcode text BarcodeSignOptions options = new BarcodeSignOptions("12345678") { // setup Barcode encoding type EncodeType = BarcodeTypes.Code128, // set signature position in absolute position LocationMeasureType = MeasureType.Millimeters, Left = 40, Top = 50, // set signature area in millimeters SizeMeasureType = MeasureType.Millimeters, Width = 20, Height = 10, // set margin in millimeters MarginMeasureType = MeasureType.Millimeters, Margin = new Padding() { Left = 5, Top = 5, Right = 5 }, }; // 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}."); } }
protected override SignOptions Create(Type objectType, JObject jObject) { SignOptions result = null; var signatureType = GetSignatureType(jObject); // check SignatureType // check for Barcode options if (signatureType == SignatureType.Barcode) { result = new BarcodeSignOptions(); } // check for QrCode options if (result == null && signatureType == SignatureType.QrCode) { result = new QrCodeSignOptions(); } // check for digital options if (result == null && signatureType == SignatureType.Digital) { result = new DigitalSignOptions(); } // check for text options if (result == null && signatureType == SignatureType.Text) { result = new TextSignOptions(); } // check for image options if (result == null && signatureType == SignatureType.Image) { result = new ImageSignOptions(); } // check for stamp options if (result == null && signatureType == SignatureType.Stamp) { result = new StampSignOptions(); } return(result); }
/// <summary> /// Following example shows how to process Barcode Signature over all signature life-cycle. /// First document is being signed with Barcode Signature, then verified for it, searched for same, updating and finally deleting this signature. /// Please be aware that this example works only on licensed product due to limitation with Barcode processing /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # ProcessingBarcodeSignatureOverCRUD : Process Barcode Signature over all signature life-cycle\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_WORDPROCESSING; string fileName = Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "ProcessingBarcodeSignatureOverCRUD", fileName); List <string> signatureIds = new List <string>(); // ----------------------------------------------------------------------------------------------------------------------------- // STEP 1. Sign document with Barcode Signature // ----------------------------------------------------------------------------------------------------------------------------- string bcText = "John Smith"; using (Signature signature = new Signature(filePath)) { BarcodeSignOptions signOptions = new BarcodeSignOptions(bcText, BarcodeTypes.Code128) { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center, Width = 100, Height = 40, Margin = new Padding(20), // set barcode color and Font ForeColor = Color.Red, Font = new SignatureFont { Size = 12, FamilyName = "Comic Sans MS" } }; // sign document to file SignResult signResult = signature.Sign(outputFilePath, signOptions); Console.WriteLine("\nDocument {filePath} was signed with following signatures:"); foreach (BaseSignature temp in signResult.Succeeded) { // collect newly created signature' Id signatureIds.Add(temp.SignatureId); Console.WriteLine($"Signature : {temp.SignatureType} Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}"); } } // ----------------------------------------------------------------------------------------------------------------------------- // STEP 2. Verify document for Barcode Signature // ----------------------------------------------------------------------------------------------------------------------------- using (Signature signature = new Signature(outputFilePath)) { BarcodeVerifyOptions verifyOptions = new BarcodeVerifyOptions() { // specify if all pages should be verified AllPages = false, PageNumber = 1, // barcode type EncodeType = BarcodeTypes.Code128, // Text = bcText }; // verify document signatures VerificationResult verifyResult = signature.Verify(verifyOptions); if (verifyResult.IsValid) { Console.WriteLine("\nDocument was verified successfully!"); } else { Helper.WriteError("\nDocument failed verification process."); } // ----------------------------------------------------------------------------------------------------------------------------- // STEP 3. Search document for Barcode Signature // ----------------------------------------------------------------------------------------------------------------------------- BarcodeSearchOptions searchOptions = new BarcodeSearchOptions() { // specify special pages to search on AllPages = true }; // search for barcode signatures in document List <BarcodeSignature> signatures = signature.Search <BarcodeSignature>(searchOptions); Console.WriteLine("\nSource document contains following Barcode signature(s)."); // enumerate all signature for output foreach (BarcodeSignature bcSignature in signatures) { if (bcSignature != null) { Console.WriteLine($"Found Barcode signature at page {bcSignature.PageNumber} with type [{bcSignature.EncodeType.TypeName}] and Barcode Text '{bcSignature.Text}'."); Console.WriteLine($"Location at {bcSignature.Left}-{bcSignature.Top}. Size is {bcSignature.Width}x{bcSignature.Height}."); } } // ----------------------------------------------------------------------------------------------------------------------------- // STEP 4. Update document Barcode Signature after searching it // ----------------------------------------------------------------------------------------------------------------------------- foreach (BarcodeSignature bcSignature in signatures) { // change position bcSignature.Left = bcSignature.Left + 100; bcSignature.Top = bcSignature.Top + 100; // change size. Please note not all documents support changing signature size bcSignature.Width = 200; bcSignature.Height = 50; } List <BaseSignature> signaturesToUpdate = signatures.ConvertAll(p => (BaseSignature)p); UpdateResult updateResult; updateResult = signature.Update(signaturesToUpdate); if (updateResult.Succeeded.Count == signatures.Count) { Console.WriteLine("\nAll signatures were successfully updated!"); } else { Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}"); Helper.WriteError($"Not updated signatures : {updateResult.Failed.Count}"); } Console.WriteLine("List of updated signatures:"); foreach (BaseSignature temp in updateResult.Succeeded) { Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}"); } // ----------------------------------------------------------------------------------------------------------------------------- // STEP 5. Update document Barcode Signature on saved SignatureId // create list of Barcode Signature by known SignatureId // ----------------------------------------------------------------------------------------------------------------------------- signaturesToUpdate.Clear(); foreach (var item in signatureIds) { BarcodeSignature temp = new BarcodeSignature(item) { Width = 150, Height = 30, Left = 100, Top = 100 }; signaturesToUpdate.Add(temp); } // update all found signatures updateResult = signature.Update(signaturesToUpdate); if (updateResult.Succeeded.Count == signatures.Count) { Console.WriteLine("\nAll signatures were successfully updated!"); } else { Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}"); Helper.WriteError($"Not updated signatures : {updateResult.Failed.Count}"); } Console.WriteLine("List of updated signatures:"); foreach (BaseSignature temp in updateResult.Succeeded) { Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}"); } // ----------------------------------------------------------------------------------------------------------------------------- // STEP 6. Delete document barcode Signature by id // create list of Barcode Signature by known SignatureId signaturesToUpdate.Clear(); foreach (var item in signatureIds) { BarcodeSignature temp = new BarcodeSignature(item); signaturesToUpdate.Add(temp); } // delete all signatures DeleteResult deleteResult = signature.Delete(signaturesToUpdate); if (deleteResult.Succeeded.Count == signaturesToUpdate.Count) { Console.WriteLine("\nAll signatures were successfully deleted!"); } else { Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}"); Helper.WriteError($"Not deleted signatures : {deleteResult.Failed.Count}"); } Console.WriteLine("List of deleted signatures:"); foreach (BaseSignature temp in deleteResult.Succeeded) { Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}"); } } }
/// <summary> /// Sign document with multiple signature types /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Basic Usage] # SignWithMultipleOptions : Sign document with multiple signature types \n"); // The path to the documents directory. string filePath = Constants.SAMPLE_WORDPROCESSING; string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithMultiple", "SignWithMultiple.docx"); using (Signature signature = new Signature(filePath)) { // define several signature options of different types and settings TextSignOptions textOptions = new TextSignOptions("Text signature") { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; BarcodeSignOptions barcodeOptions = new BarcodeSignOptions("123456") { EncodeType = BarcodeTypes.Code128, Left = 0, Top = 150, Height = 50, Width = 200 }; QrCodeSignOptions qrcodeOptions = new QrCodeSignOptions("JohnSmith") { EncodeType = QrCodeTypes.QR, Left = 0, Top = 220 }; DigitalSignOptions digitalOptions = new DigitalSignOptions(Constants.CertificatePfx) { ImageFilePath = Constants.ImageHandwrite, Left = 20, Top = 400, Height = 100, Width = 100, Password = "******" }; ImageSignOptions imageOptions = new ImageSignOptions(Constants.ImageStamp) { Left = 20, Top = 550, Height = 100, Width = 100 }; MetadataSignOptions metaOptions = new MetadataSignOptions(); WordProcessingMetadataSignature[] metaSignatures = new WordProcessingMetadataSignature[] { new WordProcessingMetadataSignature("Author", "Mr.Scherlock Holmes"), new WordProcessingMetadataSignature("CreatedOn", DateTime.Now) }; metaOptions.Signatures.AddRange(metaSignatures); // define list of signature options List <SignOptions> listOptions = new List <SignOptions>(); listOptions.Add(textOptions); listOptions.Add(barcodeOptions); listOptions.Add(qrcodeOptions); listOptions.Add(digitalOptions); listOptions.Add(imageOptions); listOptions.Add(metaOptions); // sign document to file SignResult result = signature.Sign(outputFilePath, listOptions); Console.WriteLine($"\nSource document signed successfully with {result.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}."); } }
/// <summary> /// Sign document with Barcode signature applying specific options /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # SignWithBarcodeAdvanced : Sign document with Barcode signature applying specific options\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_PDF; string fileName = Path.GetFileName(filePath); string outputPath = System.IO.Path.Combine(Constants.OutputPath, "SignWithBarcodeAdvanced"); string outputFilePath = System.IO.Path.Combine(outputPath, fileName); using (Signature signature = new Signature(filePath)) { // create barcode option with predefined barcode text BarcodeSignOptions options = new BarcodeSignOptions("12345678") { // setup Barcode encoding type EncodeType = BarcodeTypes.Code128, // set signature position Left = 100, Top = 100, // set signature alignment // when VerticalAlignment is set the Top coordinate will be ignored. // Use Margin properties Top, Bottom to provide vertical offset VerticalAlignment = Domain.VerticalAlignment.Top, // when HorizontalAlignment is set the Left coordinate will be ignored. // Use Margin properties Left, Right to provide horizontal offset HorizontalAlignment = Domain.HorizontalAlignment.Right, Margin = new Padding() { Top = 20, Right = 20 }, // adjust signature appearance // setup signature border Border = new Border() { Visible = true, Color = Color.DarkGreen, DashStyle = DashStyle.DashLongDashDot, Weight = 2 }, // set text color and Font ForeColor = Color.Red, Font = new SignatureFont { Size = 12, FamilyName = "Comic Sans MS" }, // specify position of text with barcode line CodeTextAlignment = CodeTextAlignment.Above, // setup background Background = new Background() { Color = Color.LimeGreen, Transparency = 0.5, Brush = new LinearGradientBrush(Color.LimeGreen, Color.DarkGreen) }, // set field for barcode images returning ReturnContent = true, // specify type of returned barcode images ReturnContentType = FileType.PNG }; // 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}."); Console.WriteLine("\nList of newly created signatures:"); int number = 1; foreach (BarcodeSignature barcodeSignature in signResult.Succeeded) { Console.WriteLine($"Signature #{number++}: Type: {barcodeSignature.SignatureType} Id:{barcodeSignature.SignatureId}, Location: {barcodeSignature.Left}x{barcodeSignature.Top}. Size: {barcodeSignature.Width}x{barcodeSignature.Height}"); Console.WriteLine($"Location at {barcodeSignature.Left}-{barcodeSignature.Top}. Size is {barcodeSignature.Width}x{barcodeSignature.Height}."); string outputImagePath = System.IO.Path.Combine(outputPath, $"image{number}{barcodeSignature.Format.Extension}"); using (FileStream fs = new FileStream(outputImagePath, FileMode.Create)) { fs.Write(barcodeSignature.Content, 0, barcodeSignature.Content.Length); } number++; } } }