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<Self>
pub fn open( source: impl Source + Send + Sync + 'static, options: OpenOptions, ) -> Result<Self>
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>
pub fn page_count(&self) -> Result<usize>
The number of pages.
Sourcepub fn xmp_metadata(&self) -> Result<Option<Vec<u8>>>
pub fn xmp_metadata(&self) -> Result<Option<Vec<u8>>>
The catalog’s XMP metadata packet, decoded, if present.
Sourcepub fn outlines(&self) -> Result<Vec<OutlineItem>>
pub fn outlines(&self) -> Result<Vec<OutlineItem>>
The outline (bookmark) tree.
Sourcepub fn attachments(&self) -> Result<Vec<Attachment>>
pub fn attachments(&self) -> Result<Vec<Attachment>>
The embedded files listed in the /EmbeddedFiles name tree.
Sourcepub fn attachment_data(&self, attachment: &Attachment) -> Result<Vec<u8>>
pub fn attachment_data(&self, attachment: &Attachment) -> Result<Vec<u8>>
The decoded contents of an attachment.
Source§impl Document
impl Document
Sourcepub fn select_pages(&mut self, indices: &[usize]) -> Result<()>
pub fn select_pages(&mut self, indices: &[usize]) -> Result<()>
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<()>
pub fn reorder_pages(&mut self, order: &[usize]) -> Result<()>
Moves pages into order, a permutation of 0..page_count.
Sourcepub fn delete_pages(&mut self, indices: &[usize]) -> Result<()>
pub fn delete_pages(&mut self, indices: &[usize]) -> Result<()>
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<()>
pub fn rotate_page(&mut self, index: usize, degrees: i32) -> Result<()>
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<()>
pub fn set_crop_box(&mut self, index: usize, rect: Rect) -> Result<()>
Sets a page’s crop box (the visible region).
Sourcepub fn set_media_box(&mut self, index: usize, rect: Rect) -> Result<()>
pub fn set_media_box(&mut self, index: usize, rect: Rect) -> Result<()>
Sets a page’s media box (the physical page).
Sourcepub fn append_pages_from(
&mut self,
other: &Document,
indices: Option<&[usize]>,
) -> Result<()>
pub fn append_pages_from( &mut self, other: &Document, indices: Option<&[usize]>, ) -> Result<()>
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>
pub fn extract_pages(&self, indices: &[usize]) -> Result<Document>
A new document holding copies of the pages at indices.
Sourcepub fn named_destinations(&self) -> Result<Vec<(Vec<u8>, Object)>>
pub fn named_destinations(&self) -> Result<Vec<(Vec<u8>, Object)>>
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<()>
pub fn set_outlines(&mut self, items: &[OutlineItem]) -> Result<()>
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<()>
pub fn set_info(&mut self, info: &Info) -> Result<()>
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<()>
pub fn add_attachment( &mut self, name: &str, data: &[u8], options: &AttachmentOptions, ) -> Result<()>
Embeds data as an attachment named name, replacing one of the same
name.
Sourcepub fn remove_attachment(&mut self, name: &str) -> Result<bool>
pub fn remove_attachment(&mut self, name: &str) -> Result<bool>
Removes the attachment named name; returns whether it existed.
Source§impl Document
impl Document
Sourcepub fn sanitize(&mut self, options: &SanitizeOptions) -> Result<SanitizeReport>
pub fn sanitize(&mut self, options: &SanitizeOptions) -> Result<SanitizeReport>
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.