PythonでPDFの背景を削除する

PythonでPDFの最初のページから背景アーティファクトを削除する。

背景アーティファクトを削除する

削除する前に、サブタイプが BACKGROUND のページネーションアーティファクトを集めてください。

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)

関連トピック