Menghapus latar belakang dari PDF dengan Python

Hapus artefak latar belakang dari halaman pertama PDF menggunakan Python.

Menghapus artefak latar belakang

Kumpulkan artefak paginasi dengan subtipe BACKGROUND sebelum menghapusnya.

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)

Topik terkait