Skip to main content

Importer

Struct Importer 

Source
pub struct Importer<'w, 's> { /* private fields */ }
Expand description

Copies one source document’s reachable object graph into a Writer. Every reference met through Importer::reference or Importer::copy is reserved a target number once and queued, so repeated imports from the same source dedup by source object number: one Importer per source document, and one Writer accepts several Importers in sequence.

Implementations§

Source§

impl<'w, 's> Importer<'w, 's>

Source

pub fn new( writer: &'w mut Writer, source: &'s Document, ) -> Result<Importer<'w, 's>>

Opens source for import into writer. Refuses a locked source: Document::get only decrypts transparently once a working password configured a decryptor, so copying from a locked source would emit raw ciphertext into a plain target with no /Encrypt of its own. A password-opened encrypted document copies fine: its content already reads as plaintext through Document::get, exactly what crate::encrypt_document relies on to re-encrypt it under new passwords.

Source

pub fn reference(&mut self, r: ObjRef) -> ObjRef

The target number for source reference r, reserved and queued on first sight.

Source

pub fn copy(&mut self, obj: &Object) -> Result<Object>

A copy of obj (source-space) with every reference renumbered into the target: the existing private translation, made public.

Source

pub fn substitute(&mut self, r: ObjRef, body: Object)

Replaces the source object’s body during the transplant. The body is TARGET-space and drain fills it verbatim, no renumbering: the caller translates any source refs into it via reference/copy first, and may use refs of objects already in the writer directly.

Must be called before finish drains r: once r is popped off the pending queue and filled, a later substitute for it has no effect. page cannot trigger this hazard: it only substitutes a reference it has itself just queued for the first time.

Source

pub fn finish(&mut self) -> Result<()>

Drains the pending queue; called by page/document before returning, public for callers that mixed reference in.

Source

pub fn document(&mut self) -> Result<ObjRef>

The whole reachable graph from the source catalog; returns the new root ref. Substitutions apply.

Source

pub fn page(&mut self, index: usize, parent: ObjRef) -> Result<ObjRef>

Page index as a self-contained object under parent (target-space): old /Parent replaced with parent, effective /Resources and /MediaBox materialized, /Rotate when non-zero, /CropBox when it differs from the media box, /Type /Page always present. Returns the page’s new ref. The source /Parent is dropped before translation, so none of the source’s page tree (siblings, ancestors) rides along as unreachable objects in the target.

ISO 32000 gives a page exactly one parent, so every call gets its own page object: importing the same source index again (for a second parent, or a repeat in an assembled document) never reuses an earlier call’s object, even though the resources and content beneath keep deduping through this Importer’s map. The one exception is the very first time a given indirect source page is seen: that call keeps the page’s source-graph identity (so an /Annots /P back-reference elsewhere in the graph resolves to this same object rather than a duplicate). Pages inlined into /Kids (no object of their own) always get a fresh object.

Auto Trait Implementations§

§

impl<'w, 's> !RefUnwindSafe for Importer<'w, 's>

§

impl<'w, 's> !Send for Importer<'w, 's>

§

impl<'w, 's> !Sync for Importer<'w, 's>

§

impl<'w, 's> !UnwindSafe for Importer<'w, 's>

§

impl<'w, 's> Freeze for Importer<'w, 's>

§

impl<'w, 's> Unpin for Importer<'w, 's>

§

impl<'w, 's> UnsafeUnpin for Importer<'w, 's>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.