Removing text from every page of a PDF #2489
-
I am trying to remove two lines of text at the bottom of every page of a PDF.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 19 replies
-
What do you mean by "not working"? Please note that just moving the box does not guarantee that the text will disappear, but maybe just hide it.
This highly depends on the PDF itself, although it generally should be doable if the PDF file has a valid text layer. You probably want to have a look at |
Beta Was this translation helpful? Give feedback.
-
Apologies for the ridiculously vague "not working"; I was expecting 25/72 inch to be clipped (not visible) from the bottom of each page. This variation tries (but fails) to remove an inch from the bottom of the page: from pypdf import PdfReader, PdfWriter
with open("input.pdf", "rb") as f0:
reader = PdfReader(f0)
for page in reader.pages:
page.cropbox.lower_left = (0, 72)
page.cropbox.upper_right = (595.276, 842)
writer = PdfWriter(clone_from=reader)
with open("out.pdf", "wb") as f1:
writer.write(f1) When using |
Beta Was this translation helpful? Give feedback.
What do you mean by "not working"? Please note that just moving the box does not guarantee that the text will disappear, but maybe just hide it.
This highly depends on the PDF itself, although it generally should be doable if the PDF file has a valid text layer. You probably want to have a look at
page.get_contents
andpage.replace_contents
for this.