add_redact_annot() with replace text and new font showing, "Exception: need font file or buffer" #3396
Replies: 5 comments 3 replies
-
You did not follow the instructions given in the documentation for the case of non-Base14 fonts. Inserting the font is not sufficient, you must also insert some text with your font. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. Apologies, but I'm new to PyMuPDF. Regarding your suggestion to "insert some text with your font," could you please clarify what this means? I've already mentioned that inserting text works fine with insert_textbox(). Initially, I followed your answer from https://stackoverflow.com/a/76021270/10727661, and later I switched to add_redact_annot() because my requirement is to replace text, and i know it internally calls insert_textbox(). Please help to fix this, or point me to the documentation where it helps to add new non-Base14 fonts. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Here is a script that does a similar thing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description of the bug
Below is the code I wrote to replace a specific text on a PDF using add_redact_annot(). Everything works fine if I simply call add_redact_annot() without the parameters for replacing text, font, then use insert_textbox(). I learned from the documentation that apply_redactions() will internally call insert_texbox(), so I specified the replaced text, font name, and font size on add_redact_annot(). However, it throws an error on the line apply_redactions(), saying "Exception: need font file or buffer".
Another attempt: I am using VS Code for coding. When I type, the editor suggests _apply_redactions() instead of apply_redactions(). So, I tried with _apply_redactions(). This time, there are no errors, but on the PDF the texts are successfully removed, yet not replaced.
Here is the complete Traceback
How to reproduce the bug
Using the above code.
PyMuPDF version
1.24.1
Operating system
Linux
Python version
3.10
Beta Was this translation helpful? Give feedback.
All reactions