AcroFormDocument

Struct AcroFormDocument 

Source
pub struct AcroFormDocument { /* private fields */ }
Expand description

High-level wrapper for PDF documents with forms

Implementations§

Source§

impl AcroFormDocument

Source

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")?;
Source

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);
}
Source

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 values
  • output - 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.