Skip to main content

Document

Struct Document 

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

An open PDF file. Usable only on the thread that opened it.

Implementations§

Source§

impl Document

Source

pub fn open(path: &Path) -> Result<Document>

Opens a PDF. Fails cleanly for a missing file, a file that is not a PDF, and a password-protected PDF (with NEEDS_PASSWORD). Reads the file synchronously, so callers that must not block (the UI) call it on a worker thread.

Source

pub fn open_with_password( path: &Path, password: Option<&str>, ) -> Result<Document>

Opens a PDF, unlocking it with password if it has one. A locked PDF fails with NEEDS_PASSWORD without a password and with WRONG_PASSWORD when the password doesn’t unlock it.

Source

pub fn page_count(&self) -> usize

Source

pub fn title(&self) -> Option<String>

The document’s title from its metadata, if it has one.

Source

pub fn info(&self) -> Info

The document’s metadata (title, author, dates, version and the like).

Source

pub fn page_size(&self, i: usize) -> Option<(f64, f64)>

Page i’s size in points as shown (after its rotation).

Source

pub fn page_sizes(&self) -> Vec<(f64, f64)>

Every page’s size, in order (one call for the viewer’s layout).

Source

pub fn render(&self, i: usize, scale: f64, max_px: usize) -> Result<Bitmap>

Draws page i at scale pixels per point on white, turned as the page asks, shrunk so neither side exceeds max_px.

Source

pub fn render_part( &self, i: usize, part: Rect, w: usize, h: usize, ) -> Result<Bitmap>

Draws the part part of page i (display points, so the crop box and the page’s turn are already applied) on white, filling a picture of w x h pixels. Memory follows the picture, not the page, so any zoom can be drawn for the part on screen.

Source

pub fn thumbnail(&self, i: usize, max_px: usize) -> Result<Bitmap>

A small picture of page i whose longer side is max_px.

Source

pub fn text(&self, i: usize) -> String

The text of page i (empty for a page without a text layer).

Source

pub fn search(&self, text: &str, options: SearchOptions) -> Vec<Hit>

Every match of text in the document, in reading order, with one rectangle per line it spans. An empty query finds nothing.

Source

pub fn selection( &self, page: usize, from: (f64, f64), to: (f64, f64), ) -> Selection

The text between two display points on page page (as a drag from from to to selects it) and the rectangles to highlight.

Source

pub fn outline(&self) -> Vec<OutlineEntry>

The table of contents, flattened depth-first; empty if there is none.

Source

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

The files embedded in the document: the catalog’s EmbeddedFiles name tree, then each page’s file attachment annotations. PDFKit has no API for them, so this reads the document’s objects through Core Graphics (documentRef).

Source

pub fn attachment_data(&self, i: usize) -> Result<Vec<u8>>

The bytes of attachment i of Document::attachments.

Source

pub fn layers(&self) -> Vec<Layer>

The optional content groups (“layers”) and whether the default configuration shows each.

Source

pub fn layer_tree(&self) -> Option<Vec<LayerNode>>

The layers list as a tree, from the default configuration’s /Order (see crate::layer_tree); None when it has none, and the list is then flat. Indices are those of Document::layers.

Source

pub fn set_layers(&mut self, visible: &[bool]) -> Result<()>

Chooses which layers Document::render and Document::thumbnail show, one flag per entry of Document::layers. The default choice draws the document itself; any other draws an in-memory copy with that configuration (see the ocg module). Text, search and links stay the document’s. On failure what’s drawn doesn’t change.

Page i’s link annotations: their areas and where they go (a page of this document or a URL). Links to other files are left out.

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> AutoreleaseSafe for T
where T: ?Sized,

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.