I’m currently trying to substitute a word in a PDF, i’m using fitz because it was the library that i got the closer to fixing the problem but i’m stuck. heres the code:
import fitz
doc = fitz.open([FILE HERE])
for page in doc:
areas = page.search_for("Férias")
print(page)
for area in areas:
writer = fitz.TextWriter(page, area)
writer.write_text("Vacations", fontsize=10, fontname="helv", color=(1, 1, 0))
And here is the error:
ValueError Traceback (most recent call last)
~AppDataLocalTempipykernel_137683906041629.py in ?()
2 for page in doc:
3 areas = page.search_for("Férias")
4 print(page)
5 for area in areas:
----> 6 writer = fitz.TextWriter(page, area)
7 writer.write_text("Vacations", fontsize=10, fontname="helv", color=(1, 1, 0))
8
c:Usershh100801AppDataLocalProgramsPythonPython311Libsite-packagesfitz__init__.py in ?(self, page_rect, opacity, color)
12983 self.this = mupdf.fz_new_text()
12984
12985 self.opacity = opacity
12986 self.color = color
> 12987 self.rect = Rect(page_rect)
12988 self.ctm = Matrix(1, 0, 0, -1, 0, self.rect.height)
12989 self.ictm = ~self.ctm
12990 self.last_point = Point()
c:Usershh100801AppDataLocalProgramsPythonPython311Libsite-packagesfitz__init__.py in ?(self, p0, p1, x0, y0, x1, y1, *args)
10946
10947 Explicit keyword args p0, p1, x0, y0, x1, y1 override earlier settings
10948 if not None.
...
20513 if p0 is not None: ret_x0, ret_y0 = get_xy(p0)
20514 if p1 is not None: ret_x1, ret_y1 = get_xy(p1)
20515 if x0 is not None: ret_x0 = x0
I was trying to replace a word on a PDF
New contributor
user24954473 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.