/// <summary> /// Delete Barcode signature from the document /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Basic Usage] # DeleteBarcode : Delete Barcode signature from the document \n"); // The path to the documents directory. string filePath = Constants.SAMPLE_SIGNED_MULTI; string fileName = Path.GetFileName(filePath); // copy source file since Delete method works with same Document string outputFilePath = Path.Combine(Constants.OutputPath, "DeleteBarcode", fileName); Constants.CheckDir(outputFilePath); File.Copy(filePath, outputFilePath, true); using (Signature signature = new Signature(outputFilePath)) { BarcodeSearchOptions options = new BarcodeSearchOptions(); // search for Barcode signatures in document List<BarcodeSignature> signatures = signature.Search<BarcodeSignature>(options); if (signatures.Count > 0) { BarcodeSignature barcodeSignature = signatures[0]; bool result = signature.Delete(barcodeSignature); if (result) { Console.WriteLine($"Signature with Barcode '{barcodeSignature.Text}' and encode type '{barcodeSignature.EncodeType.TypeName}' was deleted from document ['{fileName}']."); } else { Helper.WriteError($"Signature was not deleted from the document! Signature with Barcode '{barcodeSignature.Text}' and encode type '{barcodeSignature.EncodeType.TypeName}' was not found!"); } } } }
protected void CheckResponse(List <SearchBarcodeOptions> searchOptions, SearchResult result, TestFile testFile) { Assert.NotNull(result, "Result is empty."); Assert.AreEqual(result.Size, testFile.Size, "Wrong size."); Assert.NotNull(result.FileInfo, "FileInfo is null."); Assert.NotNull(String.IsNullOrEmpty(result.FileInfo?.FilePath), "FileInfo FilePath is empty."); Assert.AreEqual(testFile.Path, result.FileInfo?.FilePath, "FileInfo FilePath is wrong."); Assert.NotNull(result.Signatures, "Signatures null"); Assert.IsNotEmpty(result.Signatures, "Signatures empty"); foreach (var option in searchOptions) { bool exists = false; foreach (var signature in result.Signatures) { BarcodeSignature barcodeSignature = signature as BarcodeSignature; if (barcodeSignature != null && barcodeSignature.SignatureType.ToString() == option.SignatureType.ToString() && barcodeSignature.BarcodeType == option.BarcodeType && barcodeSignature.Text == option.Text) { exists = true; break; } } Assert.IsTrue(exists, $"Signature type {option.SignatureType} is not found"); } }
/// <summary> /// Update Barcode signature in the document by known SignatureId /// SignatureId could be obtained by Search or Sign method /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # UpdateBarcodeById : Update Barcode signature in the document by known SignatureId\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_SIGNED_MULTI; // copy source file since Update method works with same Document string fileName = Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "UpdateBarcodeById", fileName); Constants.CheckDir(outputFilePath); File.Copy(filePath, outputFilePath, true); // initialize Signature instance using (Signature signature = new Signature(outputFilePath)) { // read from some data source signature Id value string[] signatureIdList = new string[] { "07f83369-318b-41ad-a843-732417b912c2" }; // create list of Barcode Signature by known SignatureId List <BaseSignature> signatures = new List <BaseSignature>(); foreach (var item in signatureIdList) { BarcodeSignature temp = new BarcodeSignature(item); temp.Width = 150; temp.Height = 150; temp.Left = 200; temp.Top = 200; signatures.Add(temp); } // update all found signatures UpdateResult updateResult = signature.Update(signatures); if (updateResult.Succeeded.Count == signatures.Count) { Console.WriteLine("All 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}"); } } }
/// <summary> /// Update Barcode signature from the document. /// Update method supports changing Barcode location and size. /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Basic Usage] # UpdateBarcode : Update Barcode signature from the document \n"); // The path to the documents directory. string filePath = Constants.SAMPLE_SIGNED_MULTI; // copy source file since Update method works with same Document string fileName = Path.GetFileName(filePath); string outputFilePath = Path.Combine(Constants.OutputPath, "UpdateBarcode", fileName); Constants.CheckDir(outputFilePath); File.Copy(filePath, outputFilePath, true); // initialize Signature instance using (Signature signature = new Signature(outputFilePath)) { BarcodeSearchOptions options = new BarcodeSearchOptions() { Text = "12345", MatchType = TextMatchType.Contains }; List <BarcodeSignature> signatures = signature.Search <BarcodeSignature>(options); if (signatures.Count > 0) { BarcodeSignature barcodeSignature = signatures[0]; // change position barcodeSignature.Left = 100; barcodeSignature.Top = 100; // change size. Please note not all documents support changing signature size barcodeSignature.Width = 400; barcodeSignature.Height = 100; bool result = signature.Update(barcodeSignature); if (result) { Console.WriteLine($"Signature with Barcode '{barcodeSignature.Text}' and encode type '{barcodeSignature.EncodeType.TypeName}' was updated in the document ['{fileName}']."); } else { Helper.WriteError($"Signature was not updated in the document! Signature with Barcode '{barcodeSignature.Text}' and encode type '{barcodeSignature.EncodeType.TypeName}' was not found!"); } } } }
/// <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}"); } } }