Update Barcode Signatures in Document

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 for Python via .NET provides functionality to manipulate barcode signatures’ location and size. Please note that the update method modifies the same document that was passed to the constructor of the Signature class, so the example below copies the signed document first and updates the copy.

Here are the steps to update a Barcode signature in a document with GroupDocs.Signature:

  • Create a new instance of the Signature class and pass the source document path as a constructor parameter
  • Instantiate the BarcodeSearchOptions object with desired properties
  • Call the search method; the signatures property of the returned SearchResult holds the found barcode signatures
  • Select from the list the BarcodeSignature object(s) that should be updated and change their position or size
  • Call the Signature object’s update method and pass one or several signatures to it; for a single signature it returns True when the signature was updated

This example shows how to update a Barcode signature that was found using the search method:

import shutil

from groupdocs.signature import Signature
from groupdocs.signature.options import BarcodeSearchOptions


def update_barcode_signature():
    # update() saves the changes into the opened document, so work on a copy
    shutil.copy("signed.docx", "updated_barcode_signature.docx")

    with Signature("updated_barcode_signature.docx") as signature:
        options = BarcodeSearchOptions()
        # Return only signatures added by GroupDocs.Signature, not barcodes that are part of the document
        options.skip_external = True
        signatures = signature.search([options]).signatures
        print(f"Found {len(signatures)} barcode signature(s)")
        if not signatures:
            return

        barcode_signature = signatures[0]
        # Change the position
        barcode_signature.left = 60
        barcode_signature.top = 700
        # Change the size. Not all document formats support resizing a signature
        barcode_signature.width = 320
        barcode_signature.height = 80

        if signature.update(barcode_signature):
            print(f"Barcode '{barcode_signature.text}' ({barcode_signature.encode_type.type_name}) "
                  f"moved to ({barcode_signature.left}, {barcode_signature.top}) "
                  f"and resized to {barcode_signature.width}x{barcode_signature.height}")
        else:
            print(f"Barcode '{barcode_signature.text}' was not updated")


if __name__ == "__main__":
    update_barcode_signature()

signed.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 147 KB)

Download full output

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 Python library, we provide simple but powerful free online apps.

To generate barcodes and/or sign your files with barcodes for free, you can use the Barcode Generator online app.

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