Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }
Expand description

A document opened for reading.

Implementations§

Source§

impl Document

Source

pub fn open( source: impl Source + Send + Sync + 'static, options: OpenOptions, ) -> Result<Document, Error>

Opens a document from source.

Source

pub fn open_shared( source: Arc<dyn Source + Sync + Send>, options: OpenOptions, ) -> Result<Document, Error>

Opens a document from a shared source.

Source

pub fn file(&self) -> &File

The base file as read, without edits.

Source

pub fn store(&self) -> &Store

The object store: the base file plus edits.

Source

pub fn store_mut(&mut self) -> &mut Store

Mutable access to the store for low-level edits. Cached derived data (the page list) is dropped, since any edit may change it.

Source

pub fn catalog_id(&self) -> Option<ObjId>

The catalog’s id, if it is an indirect object (it always is in a valid file).

Source

pub fn catalog(&self) -> Dict

The document catalog, with edits.

Source

pub fn version(&self) -> Option<Version>

The PDF version: the header’s, or the catalog’s /Version when that is later (§7.2.2).

Source

pub fn diagnostics(&self) -> Vec<Diagnostic>

Repairs made while reading, so far.

Source

pub fn is_encrypted(&self) -> bool

Whether the file is encrypted.

Source

pub fn pages(&self) -> Result<Arc<Vec<Page>>, Error>

The pages, in order. Computed once.

Source

pub fn page_count(&self) -> Result<usize, Error>

The number of pages.

Source

pub fn info(&self) -> Info

The document information dictionary, decoded.

Source

pub fn xmp_metadata(&self) -> Result<Option<Vec<u8>>, Error>

The catalog’s XMP metadata packet, decoded, if present.

Source

pub fn outlines(&self) -> Result<Vec<OutlineItem>, Error>

The outline (bookmark) tree.

Source

pub fn attachments(&self) -> Result<Vec<Attachment>, Error>

The embedded files listed in the /EmbeddedFiles name tree.

Source

pub fn attachment_data(&self, attachment: &Attachment) -> Result<Vec<u8>, Error>

The decoded contents of an attachment.

Source§

impl Document

Source

pub fn new() -> Result<Document, Error>

A new, empty document (one empty page tree, no pages).

Source

pub fn select_pages(&mut self, indices: &[usize]) -> Result<(), Error>

Keeps the pages at indices (0-based), in that order. Pages left out are removed along with outline items and named destinations that point to them; a page listed twice is duplicated.

Source

pub fn reorder_pages(&mut self, order: &[usize]) -> Result<(), Error>

Moves pages into order, a permutation of 0..page_count.

Source

pub fn delete_pages(&mut self, indices: &[usize]) -> Result<(), Error>

Deletes the pages at indices, cleaning up outline items and named destinations that point to them.

Source

pub fn rotate_page(&mut self, index: usize, degrees: i32) -> Result<(), Error>

Rotates a page clockwise by degrees (a multiple of 90) on top of its current rotation.

Source

pub fn set_crop_box(&mut self, index: usize, rect: Rect) -> Result<(), Error>

Sets a page’s crop box (the visible region).

Source

pub fn set_media_box(&mut self, index: usize, rect: Rect) -> Result<(), Error>

Sets a page’s media box (the physical page).

Source

pub fn append_pages_from( &mut self, other: &Document, indices: Option<&[usize]>, ) -> Result<(), Error>

Appends pages of other (all of them when indices is None), copying every object they use. Objects shared by several imported pages are copied once.

Source

pub fn extract_pages(&self, indices: &[usize]) -> Result<Document, Error>

A new document holding copies of the pages at indices.

Source

pub fn named_destinations(&self) -> Result<Vec<(Vec<u8>, Object)>, Error>

Named destinations from /Dests (PDF 1.1) and the /Names /Dests name tree, keyed by name.

Source

pub fn set_outlines(&mut self, items: &[OutlineItem]) -> Result<(), Error>

Replaces the outline tree with items (ids in the items are ignored; fresh objects are written). An empty list removes the outline.

Source

pub fn set_info(&mut self, info: &Info) -> Result<(), Error>

Replaces the document information: fields that are None are removed, other entries of the Info dictionary are kept. The XMP packet is rewritten to match (D23).

Source

pub fn add_attachment( &mut self, name: &str, data: &[u8], options: &AttachmentOptions, ) -> Result<(), Error>

Embeds data as an attachment named name, replacing one of the same name.

Source

pub fn remove_attachment(&mut self, name: &str) -> Result<bool, Error>

Removes the attachment named name; returns whether it existed.

Source§

impl Document

Source

pub fn sanitize( &mut self, options: &SanitizeOptions, ) -> Result<SanitizeReport, Error>

Removes the content selected by options and reports what went. Save in full afterwards: only a full save drops the removed objects from the file.

Source§

impl Document

Source

pub fn save_to( &self, sink: &mut dyn Sink, options: &SaveOptions, ) -> Result<(), Error>

Saves the document into sink.

Source

pub fn save(&self, options: &SaveOptions) -> Result<Vec<u8>, Error>

Saves the document and returns the bytes.

Trait Implementations§

Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> ErasedDestructor for T
where T: 'static,

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> Same for T

Source§

type Output = T

Should always be Self
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.