Python에서 PDF 아티팩트 카운트

PDF 페이지에서 페이지네이션 아티팩트를 카운트하여 워터마크, 배경, 헤더 및 푸터를 확인합니다.

하위 유형별 아티팩트 수 집계

첫 페이지의 artifacts 컬렉션에서 유형이 PAGINATION인 항목을 걸러 낸 다음 하위 유형별로 개수를 세세요. 예제는 해당 하위 유형이 없으면 0을 출력합니다.

from collections import Counter
import aspose.pdf as ap

def count_pdf_artifacts(infile):
    """Count and display artifacts of different types on the first page."""
    with ap.Document(infile) as document:
        pagination_artifacts = [
            artifact
            for artifact in document.pages[1].artifacts
            if artifact.type == ap.Artifact.ArtifactType.PAGINATION
        ]

        subtypes = [artifact.subtype for artifact in pagination_artifacts]
        counts = Counter(subtypes)

        print(f"Watermarks: {counts.get(ap.Artifact.ArtifactSubtype.WATERMARK, 0)}")
        print(f"Backgrounds: {counts.get(ap.Artifact.ArtifactSubtype.BACKGROUND, 0)}")
        print(f"Headers: {counts.get(ap.Artifact.ArtifactSubtype.HEADER, 0)}")
        print(f"Footers: {counts.get(ap.Artifact.ArtifactSubtype.FOOTER, 0)}")

관련 항목