pub struct Document { /* private fields */ }Expand description
A document opened for reading.
Implementations§
Source§impl Document
impl Document
Sourcepub fn open(
source: impl Source + Send + Sync + 'static,
options: OpenOptions,
) -> Result<Document, Error>
pub fn open( source: impl Source + Send + Sync + 'static, options: OpenOptions, ) -> Result<Document, Error>
Opens a document from source.
Opens a document from a shared source.
Sourcepub fn store_mut(&mut self) -> &mut Store
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.
Sourcepub fn catalog_id(&self) -> Option<ObjId>
pub fn catalog_id(&self) -> Option<ObjId>
The catalog’s id, if it is an indirect object (it always is in a valid file).
Sourcepub fn version(&self) -> Option<Version>
pub fn version(&self) -> Option<Version>
The PDF version: the header’s, or the catalog’s /Version when that
is later (§7.2.2).
Sourcepub fn diagnostics(&self) -> Vec<Diagnostic>
pub fn diagnostics(&self) -> Vec<Diagnostic>
Repairs made while reading, so far.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Whether the file is encrypted.
Sourcepub fn page_count(&self) -> Result<usize, Error>
pub fn page_count(&self) -> Result<usize, Error>
The number of pages.
Sourcepub fn xmp_metadata(&self) -> Result<Option<Vec<u8>>, Error>
pub fn xmp_metadata(&self) -> Result<Option<Vec<u8>>, Error>
The catalog’s XMP metadata packet, decoded, if present.
Sourcepub fn attachments(&self) -> Result<Vec<Attachment>, Error>
pub fn attachments(&self) -> Result<Vec<Attachment>, Error>
The embedded files listed in the /EmbeddedFiles name tree.
Sourcepub fn attachment_data(&self, attachment: &Attachment) -> Result<Vec<u8>, Error>
pub fn attachment_data(&self, attachment: &Attachment) -> Result<Vec<u8>, Error>
The decoded contents of an attachment.
Source§impl Document
impl Document
Sourcepub fn select_pages(&mut self, indices: &[usize]) -> Result<(), Error>
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.
Sourcepub fn reorder_pages(&mut self, order: &[usize]) -> Result<(), Error>
pub fn reorder_pages(&mut self, order: &[usize]) -> Result<(), Error>
Moves pages into order, a permutation of 0..page_count.
Sourcepub fn delete_pages(&mut self, indices: &[usize]) -> Result<(), Error>
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.
Sourcepub fn rotate_page(&mut self, index: usize, degrees: i32) -> Result<(), Error>
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.
Sourcepub fn set_crop_box(&mut self, index: usize, rect: Rect) -> Result<(), Error>
pub fn set_crop_box(&mut self, index: usize, rect: Rect) -> Result<(), Error>
Sets a page’s crop box (the visible region).
Sourcepub fn set_media_box(&mut self, index: usize, rect: Rect) -> Result<(), Error>
pub fn set_media_box(&mut self, index: usize, rect: Rect) -> Result<(), Error>
Sets a page’s media box (the physical page).
Sourcepub fn append_pages_from(
&mut self,
other: &Document,
indices: Option<&[usize]>,
) -> Result<(), Error>
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.
Sourcepub fn extract_pages(&self, indices: &[usize]) -> Result<Document, Error>
pub fn extract_pages(&self, indices: &[usize]) -> Result<Document, Error>
A new document holding copies of the pages at indices.
Sourcepub fn named_destinations(&self) -> Result<Vec<(Vec<u8>, Object)>, Error>
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.
Sourcepub fn set_outlines(&mut self, items: &[OutlineItem]) -> Result<(), Error>
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.
Sourcepub fn set_info(&mut self, info: &Info) -> Result<(), Error>
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).
Sourcepub fn add_attachment(
&mut self,
name: &str,
data: &[u8],
options: &AttachmentOptions,
) -> Result<(), Error>
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§impl Document
impl Document
Sourcepub fn sanitize(
&mut self,
options: &SanitizeOptions,
) -> Result<SanitizeReport, Error>
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.