Decipher get_texttrace #2016
-
Good day everyone, Problem: Any advice is much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
You seem to be resourceful in finding new ideas. I recommend reading the documentation about |
Beta Was this translation helpful? Give feedback.
-
Alright... Either my brain is fried or I'm just having a bad day... with fitz.open(path_and_filename_of_original_pdf) as original_pdf:
final_pdf = fitz.open()
for p, page in enumerate(original_pdf, 0):
rdt = [] # list of redactions
adt = [] # list of additions
blocks = page.get_text('blocks')
blocks.sort(key=lambda block: block[1])
for b in blocks:
if b[4].contains(x):
rdt.append(b[4].strip())
if c:
cpl = True # Cripple PDF
if b[4].contains(y):
adt.append(fitz.Point(b[0], b[1]), b[4].strip())
for r in rdt:
draft = page.search_for(r)
for fnd in draft:
page.add_redact_annot(fnd)
page.apply_redactions()
page.apply_redactions(images=fitz.PDF_REDACT_IMAGE_NONE)
if cpl:
if len(blocks) > 0:
pix = page.get_pixmap(matrix=fitz.Matrix(4.16, 4.16))
jpeg = pix.pil_tobytes("JPEG", optimize=True, mode="L")
imgPDF = fitz.open("pdf", jpeg)
imgPage = final_pdf.new_page(width=rect.width, height=rect.height)
imgPage.show_pdf_page(rect, imgPDF, 0)
else:
final_pdf.new_page(width=rect.width, height=rect.height)
else:
# PASS PAGE AS-IS TO FINAL PDF
for a in adt:
page.insert_text(a[0], a[1], color=(), fontsize=7, fontname="Times-Roman")
final_pdf.save(path_and_filename_of_final_pdf, garbage=4, deflate=True, clean=True) A little hint to pass the current state of a page to the final pdf? |
Beta Was this translation helpful? Give feedback.
You seem to be resourceful in finding new ideas. I recommend reading the documentation about
get_texttrace()
to find the meaning of the dictionary items.What else do you need?