ZeroDivisionError: float division by zero when use apply_redactions() (original) (raw)
Description of the bug
Traceback (most recent call last):
File "D:\project\mytest.py", line 14, in <module>
page.apply_redactions()
File "D:\project\venv\lib\site-packages\fitz\utils.py", line 4261, in apply_redactions
trect = center_rect(annot_rect, text, fname, fsize)
File "D:\project\venv\lib\site-packages\fitz\utils.py", line 4220, in center_rect
h = math.ceil(text_width / limit) * line_height # estimate rect height
ZeroDivisionError: float division by zero
How to reproduce the bug
first put the file Equity Compensation Master.pdf Equity Compensation Master.pdf
to data/input/Equity Compensation Master.pdf
then run the code:
import fitz
import json
doc = fitz.open(filename="data/input/Equity Compensation Master.pdf")
page = doc[0]
info = json.loads(page.get_text("json"))
span = info.get("blocks")[3].get("lines")[0].get("spans")[0]
span_text = span.get("text","")
print("span: bbox=",span["bbox"]," text=",span_text)
page.add_redact_annot(span["bbox"], text="New Text", fontsize=span["size"], fill=(1, 1, 0))
page.apply_redactions()
PyMuPDF version
Built from source
Operating system
Windows
Python version
3.10