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>
impl<'w, 's> Importer<'w, 's>
Sourcepub fn new(
writer: &'w mut Writer,
source: &'s Document,
) -> Result<Importer<'w, 's>>
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.
Sourcepub fn reference(&mut self, r: ObjRef) -> ObjRef
pub fn reference(&mut self, r: ObjRef) -> ObjRef
The target number for source reference r, reserved and queued on
first sight.
Sourcepub fn copy(&mut self, obj: &Object) -> Result<Object>
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.
Sourcepub fn substitute(&mut self, r: ObjRef, body: Object)
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.
Sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
Drains the pending queue; called by page/document before
returning, public for callers that mixed reference in.
Sourcepub fn document(&mut self) -> Result<ObjRef>
pub fn document(&mut self) -> Result<ObjRef>
The whole reachable graph from the source catalog; returns the new root ref. Substitutions apply.
Sourcepub fn page(&mut self, index: usize, parent: ObjRef) -> Result<ObjRef>
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.