Finish: checkbox detection (U+F0A8) + X filling, comprehensive intake (19 Qs), scan all pages
This commit is contained in:
19
forms.py
19
forms.py
@@ -72,12 +72,21 @@ def fill_form(form_id, values):
|
||||
f = fmap.get(key)
|
||||
if not f or not text:
|
||||
continue
|
||||
text = str(text).strip()
|
||||
if not text:
|
||||
continue
|
||||
page = doc[f.get("page", 0)]
|
||||
page.insert_text((f["x"], f["y"]), text, fontsize=f.get("size", 11),
|
||||
fontname="helv", color=(0, 0, 0))
|
||||
if f.get("type") == "checkbox":
|
||||
v = str(text).strip().lower()
|
||||
if v in ("x", "true", "yes", "1", "checked", "check", "on"):
|
||||
x, y = f["x"], f["y"]
|
||||
page.draw_line(pymupdf.Point(x + 1, y + 1), pymupdf.Point(x + 9, y + 9),
|
||||
color=(0, 0, 0), width=1.3)
|
||||
page.draw_line(pymupdf.Point(x + 9, y + 1), pymupdf.Point(x + 1, y + 9),
|
||||
color=(0, 0, 0), width=1.3)
|
||||
else:
|
||||
text = str(text).strip()
|
||||
if not text:
|
||||
continue
|
||||
page.insert_text((f["x"], f["y"]), text, fontsize=f.get("size", 11),
|
||||
fontname="helv", color=(0, 0, 0))
|
||||
out = os.path.join("/tmp", f"filled_{form_id}_{uuid.uuid4().hex[:8]}.pdf")
|
||||
doc.save(out)
|
||||
doc.close()
|
||||
|
||||
Reference in New Issue
Block a user