Skip to content

Commit 1ecb356

Browse files
jbarrowopcan
andauthored
0.1.6 -- support for python>=3.10 (#21)
* test 3.9+3.10 * update formalpdf==0.1.6 for python 3.9/3.10 support * drop 3.9 support to align with onnx * Create multiline_tools.py Add utility to enable multiline text fields in fillable PDFs --------- Co-authored-by: opcan <62741296+opcan@users.noreply.github.com>
1 parent 3530216 commit 1ecb356

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
python-version: ["3.11", "3.12", "3.13"]
15+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1616

1717
steps:
1818
- name: Checkout

commonforms/multiline_tools.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pypdf import PdfReader, PdfWriter
2+
from pypdf.generic import NameObject, NumberObject
3+
4+
def enable_multiline_fields(input_pdf: str, output_pdf: str):
5+
"""
6+
Enables multiline text input on all text fields in a fillable PDF.
7+
"""
8+
reader = PdfReader(input_pdf)
9+
writer = PdfWriter()
10+
11+
for page in reader.pages:
12+
if "/Annots" in page:
13+
for annot in page["/Annots"]:
14+
obj = annot.get_object()
15+
if obj.get("/FT") == NameObject("/Tx"):
16+
current_flags = obj.get("/Ff", NumberObject(0))
17+
new_flags = int(current_flags) | 4096 # set multiline flag
18+
obj.update({NameObject("/Ff"): NumberObject(new_flags)})
19+
writer.add_page(page)
20+
21+
with open(output_pdf, "wb") as f:
22+
writer.write(f)
23+
24+
print(f"Done! Modified PDF saved as {output_pdf}")

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ name = "commonforms"
77
version = "0.1.5"
88
description = "Automatically convert a PDF into a fillable form"
99
readme = "README.md"
10-
requires-python = ">=3.11"
10+
requires-python = ">=3.10"
1111
urls = { Homepage = "https://github.com/jbarrow/commonforms" }
1212
dependencies = [
1313
"cryptography>=3.1",
14-
"formalpdf==0.1.5",
14+
"formalpdf==0.1.6",
1515
"huggingface-hub>=0.35.3",
1616
"onnx>=1.19.1",
1717
"onnxruntime>=1.23.1",

0 commit comments

Comments
 (0)