pub struct AcroFormDocument { /* private fields */ }Expand description
High-level wrapper for PDF documents with forms
Implementations§
Source§impl AcroFormDocument
impl AcroFormDocument
Sourcepub fn from_pdf<P: AsRef<Path>>(path: P) -> Result<Self, PdfError>
pub fn from_pdf<P: AsRef<Path>>(path: P) -> Result<Self, PdfError>
Load a PDF document from a file path
§Example
use acroform::AcroFormDocument;
let doc = AcroFormDocument::from_pdf("form.pdf")?;Sourcepub fn fields(&self) -> Vec<FormField>
pub fn fields(&self) -> Vec<FormField>
Get all fillable fields in the document
Returns a list of all terminal fields (fields that can be filled). Parent/container fields are not included.
§Example
use acroform::AcroFormDocument;
let doc = AcroFormDocument::from_pdf("form.pdf")?;
for field in doc.fields() {
println!("Field: {} ({:?})", field.name, field.field_type);
}Sourcepub fn fill_and_save<P: AsRef<Path>>(
&mut self,
values: HashMap<String, FieldValue>,
output: P,
) -> Result<(), PdfError>
pub fn fill_and_save<P: AsRef<Path>>( &mut self, values: HashMap<String, FieldValue>, output: P, ) -> Result<(), PdfError>
Fill form fields and save to a new file
Updates the specified fields with new values and saves the result. Deletes existing appearance streams (/AP) to force PDF viewers to regenerate them. This ensures consistent behavior across different PDF viewers.
§Arguments
values- Map of field names to new valuesoutput- Output file path
§Example
use acroform::{AcroFormDocument, FieldValue};
use std::collections::HashMap;
let mut doc = AcroFormDocument::from_pdf("form.pdf")?;
let mut values = HashMap::new();
values.insert("name".to_string(), FieldValue::Text("John Doe".to_string()));
values.insert("age".to_string(), FieldValue::Integer(30));
doc.fill_and_save(values, "filled.pdf")?;Auto Trait Implementations§
impl Freeze for AcroFormDocument
impl RefUnwindSafe for AcroFormDocument
impl Send for AcroFormDocument
impl Sync for AcroFormDocument
impl Unpin for AcroFormDocument
impl UnwindSafe for AcroFormDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more