Supprimer les arrière-plans PDF en Python

Supprimer les artefacts d’arrière-plan de la première page d’un PDF en Python.

Supprimer les artefacts d’arrière-plan

Recueillez les artefacts de pagination du sous-type BACKGROUND avant de les supprimer.

import aspose.pdf as ap

def remove_background(infile, outfile):
    with ap.Document(infile) as document:
        backgrounds = [
            artifact
            for artifact in document.pages[1].artifacts
            if artifact.type == ap.Artifact.ArtifactType.PAGINATION
            and artifact.subtype == ap.Artifact.ArtifactSubtype.BACKGROUND
        ]

        for background in backgrounds:
            document.pages[1].artifacts.delete(background)

        document.save(outfile)

Rubriques connexes