This example shows how to make advanced search for Barcode signature in the document with enabled options to grab barcode electronic signature context.
using(Signaturesignature=newSignature("sample.pdf")){BarcodeSearchOptionsoptions=newBarcodeSearchOptions(){// specify special pages to search onAllPages=false,// single page numberPageNumber=1,// setup extended search in pages setupPagesSetup=newPagesSetup(){FirstPage=true,LastPage=true,OddPages=false,EvenPages=false},// specify special barcode type to searchEncodeType=BarcodeTypes.Code39Standard,// specify text match typeMatchType=TextMatchType.Contains,// specify text pattern to searchText="12345678",// set field for barcode images returningReturnContent=true,// specify type of returned barcode imagesReturnContentType=FileType.PNG};// search for signatures in documentList<BarcodeSignature>signatures=signature.Search<BarcodeSignature>(options);Console.WriteLine("\nSource document contains following signatures.");foreach(varbarcodeSignatureinsignatures){Console.WriteLine("Barcode signature found at page {0} with type {1} and text {2}",barcodeSignature.PageNumber,barcodeSignature.EncodeType,barcodeSignature.Text);Console.WriteLine("Barcode signature size {0} and format {1}",barcodeSignature.Content?.Length,barcodeSignature.Format);Console.WriteLine($"Location at {barcodeSignature.Left}-{barcodeSignature.Top}. Size is {barcodeSignature.Width}x{barcodeSignature.Height}.");}//Save Barcode imagesstringoutputPath=Path.Combine(Constants.OutputPath,"SearchForBarcodeAdvanced");if(!Directory.Exists(outputPath)){Directory.CreateDirectory(outputPath);}inti=0;foreach(BarcodeSignaturebarcodeSignatureinsignatures){if(barcodeSignature.Content!=null){stringoutputFilePath=Path.Combine(outputPath,$"image{i}{barcodeSignature.Format?.Extension}");using(FileStreamfs=newFileStream(outputFilePath,FileMode.Create)){fs.Write(barcodeSignature.Content,0,barcodeSignature.Content.Length);}}i++;}}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in ourΒ GitHub examples: