Advanced search for Barcode signatures

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Signature MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-signature -- dnx GroupDocs.Signature.Mcp --yes
Folders, licensing and more →

GroupDocs.Signature provides BarcodeSearchOptions class to specify different options to search for Barcode Signatures.

Here are the steps to search for barcode signatures within the document with GroupDocs.Signature:

This example shows how to make advanced search for Barcode signature in the document with enabled options to grab barcode electronic signature context.

The options use PagesSetup to select pages, BarcodeTypes to set the barcode type, TextMatchType to set how the text is matched, and FileType to set the format of the returned barcode images.

using (Signature signature = new Signature("sample.pdf"))
{
    BarcodeSearchOptions options = new BarcodeSearchOptions()
    {
        // specify special pages to search on
        AllPages = false,
        // single page number
        PageNumber = 1,
        // setup extended search in pages setup
        PagesSetup = new PagesSetup() { FirstPage = true, LastPage = true, OddPages = false, EvenPages = false },
        // specify special barcode type to search
        EncodeType = BarcodeTypes.Code39Standard,
        // specify text match type
        MatchType = TextMatchType.Contains,
        // specify text pattern to search
        Text = "12345678",
        // set field for barcode images returning
        ReturnContent = true,
        // specify type of returned barcode images
        ReturnContentType = FileType.PNG
    };
    // search for signatures in document
    List<BarcodeSignature> signatures = signature.Search<BarcodeSignature>(options);
    Console.WriteLine("\nSource document contains following signatures.");
    foreach (var barcodeSignature in signatures)
    {
        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 images
    string outputPath = Path.Combine(Constants.OutputPath, "SearchForBarcodeAdvanced");
    if (!Directory.Exists(outputPath))
    {
        Directory.CreateDirectory(outputPath);
    }
    int i = 0;
    foreach (BarcodeSignature barcodeSignature in signatures)
    {
        if (barcodeSignature.Content != null)
        {
            string outputFilePath = Path.Combine(outputPath, $"image{i}{barcodeSignature.Format?.Extension}");
            using (FileStream fs = new FileStream(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:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.