diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f300e48..f83175f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.11", "3.12", "3.13"] + python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - name: Checkout diff --git a/commonforms/multiline_tools.py b/commonforms/multiline_tools.py new file mode 100644 index 0000000..37b2944 --- /dev/null +++ b/commonforms/multiline_tools.py @@ -0,0 +1,24 @@ +from pypdf import PdfReader, PdfWriter +from pypdf.generic import NameObject, NumberObject + +def enable_multiline_fields(input_pdf: str, output_pdf: str): + """ + Enables multiline text input on all text fields in a fillable PDF. + """ + reader = PdfReader(input_pdf) + writer = PdfWriter() + + for page in reader.pages: + if "/Annots" in page: + for annot in page["/Annots"]: + obj = annot.get_object() + if obj.get("/FT") == NameObject("/Tx"): + current_flags = obj.get("/Ff", NumberObject(0)) + new_flags = int(current_flags) | 4096 # set multiline flag + obj.update({NameObject("/Ff"): NumberObject(new_flags)}) + writer.add_page(page) + + with open(output_pdf, "wb") as f: + writer.write(f) + + print(f"Done! Modified PDF saved as {output_pdf}") \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a4e46ec..d60490c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,11 +7,11 @@ name = "commonforms" version = "0.1.5" description = "Automatically convert a PDF into a fillable form" readme = "README.md" -requires-python = ">=3.11" +requires-python = ">=3.10" urls = { Homepage = "https://github.com/jbarrow/commonforms" } dependencies = [ "cryptography>=3.1", - "formalpdf==0.1.5", + "formalpdf==0.1.6", "huggingface-hub>=0.35.3", "onnx>=1.19.1", "onnxruntime>=1.23.1",