TextWrite.fill_textbox() error: wrong handling of empty input
Describe the bug (mandatory)
Writer.fill_textbox() is unusable for PyMuPPDF 1.19.2.
To Reproduce (mandatory)
- Python 3.9.2
- Pymupdf 1.19.2 writer = fitz.TextWriter(page.rect, color=color) writer.fill_textbox(new_area, variable, fontsize=fontsize, warn=True, align=align, font=font)
Expected behavior (optional)
Page should successfully redact as it did before upgrading to 1.19.2.
Screenshots (optional)
If applicable, add screenshots to help explain your problem.
Your configuration (mandatory)
- Docker, Flask, python 3.9
- Pymupdf 1.19.2
File "/app/prosebit/blueprints/api/pymupdf.py", line 968, in apply_overlay writer.fill_textbox(new_area, variable, fontsize=fontsize, File "/home/python/.local/lib/python3.9/site-packages/fitz/utils.py", line 4412, in fill_textbox return new_lines[i + 1 :] # return non-written lines UnboundLocalError: local variable 'i' referenced before assignmen
Cannot reproduce: My test scripts work for 1.19.2 whether or not the target rectangle is large enough to contain all or some lines only.
Page should successfully redact as it did before upgrading to 1.19.2.
What is the meaning of redactions (annotations?) in this context?
BTW: UnboundLocalError can only happen, if the list new_lines is empty.
I am going to change that part anyway for the next version.
As a hotfix you may want to do i = 0 before the start of loop, in line 4385.
Yes the issue was an empty string was being passed to fill_textbox to create an empty redaction. sending ' ' seemed to fix the issue.
I will keep this issue open, because invalid input like yours should be coped with better. In addition, counting and returning lines that did not fit ninto the textbox was not correct.
New version 1.19.3 is being uploaded to PyPI.