View Single Post
Old 05-14-2023, 04:45 PM   #12
Shohreh
Addict
Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.Shohreh ought to be getting tired of karma fortunes by now.
 
Posts: 207
Karma: 304158
Join Date: Jan 2016
Location: France
Device: none
And do the same for the footer on all the pages:

Code:
import fitz
import sys

doc = fitz.open("original.pdf")

"""
#Until a PDF viewer comes along… here's how to find where to draw a box around the header+footer
#left,top,right,bottom
rect = fitz.Rect(0,560,424,600)
page = doc[13]
shape = page.new_shape()
shape.drawRect(rect)
shape.finish(color=None)
shape.commit()
"""

rect_header = fitz.Rect(0,0,424,50)
rect_footer = fitz.Rect(0,560,424,600)
exclude = [range(1, 14), 17,24,97,155,186,232,258,297,322,343,404]
for index in range(1,doc.page_count):
	print(index)
	page = doc[index]

	#remove header only on non-chapter pages
	if index not in exclude:
		page.add_redact_annot(rect_header)

	#remove footer on all pages
	page.add_redact_annot(rect_footer)
	page.apply_redactions()
	
doc.save("redacted.pdf")
Shohreh is offline   Reply With Quote