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 open_interactive(pdf_bytes: &[u8]) -> Result<XfaSession, XfaError>
pub fn open_interactive(pdf_bytes: &[u8]) -> Result<XfaSession, XfaError>
Open a session in interactive mode (Phase 2).
Identical to open, then — when the xfa-js-sandboxed
feature is compiled in — runs the interactive open lifecycle
(initialize → docReady → calculate) with field.presence writes
landing in the tree, re-layouts, and re-enumerates. The result reflects
a dynamic form’s real initial visible state (the script-driven
show/hide of conditional sections), not the static one-shot render.
Without the feature this is equivalent to open and
commit_value degrades to a value write plus
re-layout (no script-driven toggles).
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 is_interactive(&self) -> bool
pub fn is_interactive(&self) -> bool
Whether interactive mode is active (the open lifecycle ran with presence
writes and commits dispatch user-edit scripts). Only ever true with the
xfa-js-sandboxed feature compiled in.
Sourcepub fn commit_value(
&mut self,
name: &str,
value: XfaWriteValue<'_>,
) -> Result<XfaCommitOutcome, XfaError>
pub fn commit_value( &mut self, name: &str, value: XfaWriteValue<'_>, ) -> Result<XfaCommitOutcome, XfaError>
Phase 2 interactive commit. Set a field’s value, then run the
dynamic effects: fire the field’s change/click scripts, a global
calculate pass, re-layout, and re-enumerate the field/page model.
This is the interactive analogue of set_value: the
data writeback is identical (so save_to_bytes
still produces an Acrobat-reopenable PDF), but conditional sections that
the committed value reveals or hides are reflected in the new
fields / page_count.
Without the xfa-js-sandboxed feature this degrades to a value write
plus re-layout: interactive == false, scripts_executed == 0, and no
script-driven presence changes (a static value edit only).
Sourcepub fn script_report(&self) -> &XfaScriptReport
pub fn script_report(&self) -> &XfaScriptReport
Scripts that did not run, over the whole session so far: FormCalc and other non-JavaScript scripts that were due, and JavaScript scripts that threw, timed out or were refused. Each script is counted once. Empty until the session is interactive.
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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