pub struct XfaSession { /* private fields */ }Expand description
Parse-once session over a single XFA PDF.
Holds the extracted packets, the parsed datasets DOM, the merged form tree, and the layout result. Field enumeration and value writes operate on the cached state; no re-parse or re-layout happens per call (Phase 1: value writes do not reflow the layout).
Implementations§
Source§impl XfaSession
impl XfaSession
Sourcepub fn open(pdf_bytes: &[u8]) -> Result<XfaSession, XfaError>
pub fn open(pdf_bytes: &[u8]) -> Result<XfaSession, XfaError>
Open a session over the given PDF bytes.
Mirrors the flatten pipeline’s Extract → Bind → (static scripts) → saved-form-state → Layout stages, then caches everything.
Returns XfaError::PacketNotFound when the PDF has no XFA template
packet (i.e. it is not an XFA form).
Sourcepub fn page_count(&self) -> usize
pub fn page_count(&self) -> usize
Number of pages in the cached layout result.
Sourcepub fn page_size(&self, page: usize) -> Option<(f64, f64)>
pub fn page_size(&self, page: usize) -> Option<(f64, f64)>
Page dimensions (width, height) in points for a 0-based page index.
Sourcepub fn fields(&self) -> &[XfaFieldModel]
pub fn fields(&self) -> &[XfaFieldModel]
The enumerated field models, in document order.
Sourcepub fn field(&self, name: &str) -> Option<&XfaFieldModel>
pub fn field(&self, name: &str) -> Option<&XfaFieldModel>
Look up one field model by fully-qualified name. Accepts both the
display name (a.b[2].c) and the explicit SOM path (a[0].b[2].c[0]).
Sourcepub fn set_value(
&mut self,
name: &str,
value: XfaWriteValue<'_>,
) -> Result<XfaSetOutcome, XfaError>
pub fn set_value( &mut self, name: &str, value: XfaWriteValue<'_>, ) -> Result<XfaSetOutcome, XfaError>
Set a field’s value.
Updates the form-tree raw value, writes through to the bound
datasets node (creating it on demand for default-bound fields), and
records the change for save_to_bytes.
Rejects writes to read-only fields (XfaError::FieldReadOnly) and
to non-fillable kinds (buttons, signatures, …). No change/click
scripts run and the layout is not recomputed (Phase 1).
Sourcepub fn save_to_bytes(&self) -> Result<Vec<u8>, XfaError>
pub fn save_to_bytes(&self) -> Result<Vec<u8>, XfaError>
Serialize the updated datasets (and form-packet value syncs) into a copy of the original PDF and return the new bytes.
Sourcepub fn write_into_document(
&self,
doc: &mut Document,
) -> Result<XfaWritebackReport, XfaError>
pub fn write_into_document( &self, doc: &mut Document, ) -> Result<XfaWritebackReport, XfaError>
Apply the datasets/form-packet writeback to an already-loaded
lopdf::Document (the SDK facade path: the caller owns the document
and serializes it itself).
Auto Trait Implementations§
impl Freeze for XfaSession
impl RefUnwindSafe for XfaSession
impl Send for XfaSession
impl Sync for XfaSession
impl Unpin for XfaSession
impl UnsafeUnpin for XfaSession
impl UnwindSafe for XfaSession
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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