JFLib

pdf/src/edit/full.rs#

Source: lib/pdf/src/edit/full.rs

edit::full -- a document written again in full (Update::save_full): every object the trailer
reaches (/Root, /Info), as the update has it, in a new file with one cross-reference section.
What no object reaches any longer, and the older revisions of the incremental updates, are
left out; the objects keep their numbers (the section lists the runs of numbers there are, so
a number far up costs nothing between), and the new ones (object streams, /Encrypt, a direct
/Root) come after every number an object refers to, also of objects deleted or missing.  A file whose newest section is a cross-reference
stream, or that has object streams, gets object streams (of up to 100 objects) and a
cross-reference stream again; any other a table.

  let out = up.save_full(&Full::default())?;                              // its encryption
  let out = up.save_full(&Full { security: Security::None, ..Full::default() })?;  // decrypted
  let out = up.save_full(&Full { security: Security::Encrypt(&enc), ..Full::default() })?;

Security::Keep keeps /Encrypt, the key and the first /ID string, and copies the streams that
stay the same objects as they are; Security::None and Security::Encrypt decrypt every string
and stream (a /Crypt filter of a stream is taken off; bytes AES cannot have made are an error,
not an empty stream; no bytes at all are an empty stream, as viewers read them) and write them in the clear or with the new key.  Changing or removing the
encryption of an encrypted file needs the owner password (read::Document::opened_as_owner), as
viewers ask for it.  A file with signatures (a signed field of the document as it was opened, a
signature dictionary with /ByteRange anywhere the trailer reaches now, usage rights or a
certification in /Perms) is not written in full unless Full::break_signatures: the bytes they
cover are gone, so they no longer verify.  The first /ID string stays (a new file has it from
the bytes, or from the seed when it is encrypted); the second is a hash of the new bytes.
AES-256 in a file older than PDF 2.0 adds Adobe's extension level 8 to the catalog, as the
writer does.  Objects go into object streams only where their strings stay as protected as
they were (not when a file encrypts strings but not streams), and the catalog of an encrypted
file stays out of them (ISO 32000-2, 7.5.7).
  • enum Security<'e> the encryption of a document written in full

    • Keep -- as the document has it (its /Encrypt and key; none when it has none)
    • None -- not encrypted
    • Encrypt(&'e crate::Encryption) -- encrypted anew
  • struct Full<'e> how save_full writes the document

    • security: Security<'e>
    • break_signatures: bool -- write a document with signatures although they will not verify (save_full refuses it otherwise)

impl Update<'_>

  • fn save_full(&self, opts: &Full) -> Result<Vec<u8>, Error> the document written again in full, with the update's changes (see edit::full)

Source: docs/API.md in the JFLib repository.