Add background to PDF with Python

Contents
[ ]

Background images can be used to add a watermark, or other subtle design, to documents. In Aspose.PDF for Python via .NET, each PDF document is a collection of pages and each page contains a collection of artifacts. The BackgroundArtifact class can be used to add a background image to a page object.

The following code snippet shows how to add a background image to PDF pages using the BackgroundArtifact object with Python.


    import aspose.pdf as ap

    # Create a new Document object
    document = ap.Document()

    # Add a new page to document object
    page = document.pages.add()

    # Create Background Artifact object
    background = ap.BackgroundArtifact()

    # Specify the image for backgroundartifact object
    background.background_image = io.FileIO(input_image_file)

    # Add backgroundartifact to artifacts collection of page
    page.artifacts.append(background)

    # Save the document
    document.save(output_pdf)