Remove PDF Headers and Footers in Python
Contents
[
Hide
]
Remove header and footer artifacts from the first page of a PDF in Python.
Remove header and footer artifacts
Collect pagination artifacts with the HEADER or FOOTER subtype before deleting them.
import aspose.pdf as ap
def delete_header_footer_artifact(infile, outfile):
with ap.Document(infile) as document:
header_footers = [
artifact
for artifact in document.pages[1].artifacts
if artifact.type == ap.Artifact.ArtifactType.PAGINATION
and (
artifact.subtype == ap.Artifact.ArtifactSubtype.HEADER
or artifact.subtype == ap.Artifact.ArtifactSubtype.FOOTER
)
]
for art in header_footers:
document.pages[1].artifacts.delete(art)
document.save(outfile)