From 8102f48b5aaf6965a37814c55f728711382661f2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 11 Apr 2021 03:48:02 +0200 Subject: Fill in the form's fields with the fields' IDs Use a copy of Form 1040 as a sample. A copy of the PDF is produced so you can reference the text fields by their ID. --- src/main.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e7a11a9..2713df4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,15 @@ +use pdf_forms::{Form, FieldType}; + fn main() { - println!("Hello, world!"); + let mut form = Form::load("./f1040.pdf").unwrap(); + + for i in 0..form.len() { + let field_type = form.get_type(i); + + if let FieldType::Text = field_type { + form.set_text(i, format!("{}", i)).unwrap(); + } + } + + form.save("./f1040-new.pdf").unwrap(); } -- cgit v1.2.3