إزالة الخلفيات من 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)

مواضيع ذات صلة