Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ commonforms <input.pdf> <output.pdf>
| `--image-size` | int | `1600` | Image size for inference |
| `--confidence` | float | `0.3` | Confidence threshold for detection |
| `--fast` | flag | `False` | If running on a CPU, you can trade off accuracy for speed and run in about half the time |
| `--multiline` | flag | `False` | If you want the detected textboxes to allow multiline inputs |


## CommonForms API
Expand Down
6 changes: 6 additions & 0 deletions commonforms/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def main():
action="store_true",
help="If running on a CPU, you can use --fast to get a 50% speedup with a small accuracy penalty",
)
parser.add_argument(
"--multiline",
action="store_true",
help="If you want the detected textboxes to allow multiline inputs.",
)

args = parser.parse_args()

Expand All @@ -63,6 +68,7 @@ def main():
image_size=args.image_size,
confidence=args.confidence,
fast=args.fast,
multiline=args.multiline,
)


Expand Down
3 changes: 2 additions & 1 deletion commonforms/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def prepare_form(
image_size: int = 1600,
confidence: float = 0.3,
fast: bool = False,
multiline: bool = False,
):
detector = FFDNetDetector(model_or_path, device=device, fast=fast)

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

if widget.widget_type == "TextBox":
writer.add_text_box(name, page_ix, widget.bounding_box)
writer.add_text_box(name, page_ix, widget.bounding_box, multiline=multiline)
elif widget.widget_type == "ChoiceButton":
writer.add_checkbox(name, page_ix, widget.bounding_box)
elif widget.widget_type == "Signature":
Expand Down
24 changes: 0 additions & 24 deletions commonforms/multiline_tools.py

This file was deleted.

13 changes: 13 additions & 0 deletions tests/inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ def test_inference_fast(tmp_path):
doc.document.close()


def test_mutlinline(tmp_path):
output_path = tmp_path / "output.pdf"
commonforms.prepare_form("./tests/resources/input.pdf", output_path, fast=True, multiline=True)

assert output_path.exists()

doc = formalpdf.open(output_path)
assert len(doc[0].widgets()) > 0

doc.document.close()



def test_encrypted_failure(tmp_path):
# Reminder to future Joe: password for encrypted PDF is "kanbanery"
output_path = tmp_path / "output.pdf"
Expand Down