Adding Bates Numbering Artifact in Python via .NET

Bates numbering is widely used in legal, medical, and business workflows to assign unique, sequential identifiers to pages within a document set. Aspose.PDF for Python via .NET offers a simple and flexible API for automating this process, enabling you to apply standardized Bates numbers programmatically across any PDF.

Using the BatesNArtifact class, developers can fully customize numbering behavior—including the starting number, digit count, prefixes and suffixes, alignment, and margins. Once configured, the artifact can be applied to the document through the ‘add_bates_numbering’ method on the ‘PageCollection’ or added as part of a list of pagination artifacts. Aspose.PDF also supports a delegate-based configuration style, allowing for dynamic control of artifact settings at runtime.

In addition to creating Bates numbers, the API provides an easy way to remove them using ‘delete_bates_numbering’, offering complete flexibility in document processing workflows.

This article shows multiple methods for adding and removing Bates numbering in a PDF using Aspose.PDF for Python via .NET, with clear examples of artifact configuration, application, and removal.

Adding Bates Numbering Artifact

This example shows how to programmatically add Bates numbering to a PDF document using Aspose.PDF for Python via .NET. By configuring a BatesNArtifact with the desired settings and applying it to the document’s pages, you can automate the process of adding standardized identifiers to each page.

To add a Bates-numbering artifact to a document, call the AddBatesNumbering(BatesNArtifact) extension method on the PageCollection, passing a BatesNArtifact instance as the parameter:


import aspose.pdf as ap

def add_bates_numbering(path_outfile):
    # Create a new or empty PDF document
    with ap.Document() as document:

        # Add 10 blank pages
        for _ in range(10):
            document.pages.add()

        # Create Bates numbering artifact
        bates = ap.BatesNArtifact(
            start_page=1,
            end_page=0,  # 0 = apply until last page
            subset=ap.Subset.ALL,
            number_of_digits=6,
            start_number=1,
            prefix="",
            suffix="",
            artifact_vertical_alignment=ap.VerticalAlignment.BOTTOM,
            artifact_horizontal_alignment=ap.HorizontalAlignment.RIGHT,
            right_margin=72,
            left_margin=72,
            top_margin=36,
            bottom_margin=36
        )

        # Add Bates numbering to all pages
        document.pages.add_bates_numbering(bates)

        # Save the resulting PDF
        document.save(path_outfile)

Or, you can pass a collection of PaginationArtifacts:


import aspose.pdf as ap

def add_bates_numbering_collection(path_outfile):
    with ap.Document() as document:

        # Add 10 pages
        for _ in range(10):
            document.pages.add()

        # Create Bates artifact
        bates = ap.BatesNArtifact(
            start_page=1,
            end_page=0,
            subset=ap.Subset.ALL,
            number_of_digits=6,
            start_number=1,
            prefix="",
            suffix="",
            artifact_vertical_alignment=ap.VerticalAlignment.BOTTOM,
            artifact_horizontal_alignment=ap.HorizontalAlignment.RIGHT,
            right_margin=72,
            left_margin=72,
            top_margin=36,
            bottom_margin=36
        )

        # Add as a pagination artifact list
        document.pages.add_pagination([bates])

        # Save document
        document.save(path_outfile)

Add a Bates numbering artifact using an action delegate:


import aspose.pdf as ap

def add_bates_numbering_delegate(path_outfile):
    def configure_bates(b):
        """Configure Bates numbering artifact with desired settings."""
        b.start_page = 1
        b.end_page = 0
        b.subset = ap.Subset.ALL
        b.number_of_digits = 6
        b.start_number = 1
        b.prefix = ""
        b.suffix = ""
        b.artifact_vertical_alignment = ap.VerticalAlignment.BOTTOM
        b.artifact_horizontal_alignment = ap.HorizontalAlignment.RIGHT
        b.right_margin = 72
        b.left_margin = 72
        b.top_margin = 36
        b.bottom_margin = 36
        b.text_state.font_size = 10
    
    with ap.Document() as document:

        # Add 10 pages
        for _ in range(10):
            document.pages.add()

        # Use delegate function to configure Bates artifact
        document.pages.add_bates_numbering(configure_bates)

        # Save output PDF
        document.save(path_outfile)

Delete Bates Numbering


import aspose.pdf as ap

def delete_bates_numbering(path_infile, path_outfile):
    with ap.Document(path_infile) as document:

        # Remove Bates numbering from all pages
        document.pages.delete_bates_numbering()

        # Save updated document
        document.save(path_outfile)