Skip to content

Commit 3530216

Browse files
authored
Merge pull request #23 from jbarrow/multiline
add multiline support for #11
2 parents b0cc4d4 + f182f25 commit 3530216

5 files changed

Lines changed: 22 additions & 25 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ commonforms <input.pdf> <output.pdf>
4747
| `--image-size` | int | `1600` | Image size for inference |
4848
| `--confidence` | float | `0.3` | Confidence threshold for detection |
4949
| `--fast` | flag | `False` | If running on a CPU, you can trade off accuracy for speed and run in about half the time |
50+
| `--multiline` | flag | `False` | If you want the detected textboxes to allow multiline inputs |
5051

5152

5253
## CommonForms API

commonforms/__main__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def main():
5050
action="store_true",
5151
help="If running on a CPU, you can use --fast to get a 50% speedup with a small accuracy penalty",
5252
)
53+
parser.add_argument(
54+
"--multiline",
55+
action="store_true",
56+
help="If you want the detected textboxes to allow multiline inputs.",
57+
)
5358

5459
args = parser.parse_args()
5560

@@ -63,6 +68,7 @@ def main():
6368
image_size=args.image_size,
6469
confidence=args.confidence,
6570
fast=args.fast,
71+
multiline=args.multiline,
6672
)
6773

6874

commonforms/inference.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def prepare_form(
166166
image_size: int = 1600,
167167
confidence: float = 0.3,
168168
fast: bool = False,
169+
multiline: bool = False,
169170
):
170171
detector = FFDNetDetector(model_or_path, device=device, fast=fast)
171172

@@ -187,7 +188,7 @@ def prepare_form(
187188
name = f"{widget.widget_type.lower()}_{widget.page}_{i}"
188189

189190
if widget.widget_type == "TextBox":
190-
writer.add_text_box(name, page_ix, widget.bounding_box)
191+
writer.add_text_box(name, page_ix, widget.bounding_box, multiline=multiline)
191192
elif widget.widget_type == "ChoiceButton":
192193
writer.add_checkbox(name, page_ix, widget.bounding_box)
193194
elif widget.widget_type == "Signature":

commonforms/multiline_tools.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/inference_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ def test_inference_fast(tmp_path):
3030
doc.document.close()
3131

3232

33+
def test_mutlinline(tmp_path):
34+
output_path = tmp_path / "output.pdf"
35+
commonforms.prepare_form("./tests/resources/input.pdf", output_path, fast=True, multiline=True)
36+
37+
assert output_path.exists()
38+
39+
doc = formalpdf.open(output_path)
40+
assert len(doc[0].widgets()) > 0
41+
42+
doc.document.close()
43+
44+
45+
3346
def test_encrypted_failure(tmp_path):
3447
# Reminder to future Joe: password for encrypted PDF is "kanbanery"
3548
output_path = tmp_path / "output.pdf"

0 commit comments

Comments
 (0)