Menghitung artefak paginasi pada PDF dengan Python
Contents
[
Hide
]
Hitung artefak paginasi pada halaman PDF untuk memeriksa tanda air, latar belakang, header, dan footer.
Menghitung artefak berdasarkan subtipe
Saring koleksi artifacts pada halaman pertama berdasarkan tipe PAGINATION, lalu hitung artefak per subtipe. Contoh ini mencetak nol jika suatu subtipe tidak ditemukan.
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)}")