pub struct Document { /* private fields */ }Expand description
An open PDF file. Usable only on the thread that opened it.
Implementations§
Source§impl Document
impl Document
Sourcepub fn open(path: &Path) -> Result<Document>
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.
Sourcepub fn open_with_password(
path: &Path,
password: Option<&str>,
) -> Result<Document>
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.
pub fn page_count(&self) -> usize
Sourcepub fn info(&self) -> Info
pub fn info(&self) -> Info
The document’s metadata (title, author, dates, version and the like).
Sourcepub fn page_size(&self, i: usize) -> Option<(f64, f64)>
pub fn page_size(&self, i: usize) -> Option<(f64, f64)>
Page i’s size in points as shown (after its rotation).
Sourcepub fn page_sizes(&self) -> Vec<(f64, f64)>
pub fn page_sizes(&self) -> Vec<(f64, f64)>
Every page’s size, in order (one call for the viewer’s layout).
Sourcepub fn render(&self, i: usize, scale: f64, max_px: usize) -> Result<Bitmap>
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.
Sourcepub fn render_part(
&self,
i: usize,
part: Rect,
w: usize,
h: usize,
) -> Result<Bitmap>
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.
Sourcepub fn thumbnail(&self, i: usize, max_px: usize) -> Result<Bitmap>
pub fn thumbnail(&self, i: usize, max_px: usize) -> Result<Bitmap>
A small picture of page i whose longer side is max_px.
Sourcepub fn text(&self, i: usize) -> String
pub fn text(&self, i: usize) -> String
The text of page i (empty for a page without a text layer).
Sourcepub fn search(&self, text: &str, options: SearchOptions) -> Vec<Hit>
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.
Sourcepub fn selection(
&self,
page: usize,
from: (f64, f64),
to: (f64, f64),
) -> Selection
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.
Sourcepub fn outline(&self) -> Vec<OutlineEntry>
pub fn outline(&self) -> Vec<OutlineEntry>
The table of contents, flattened depth-first; empty if there is none.
Sourcepub fn attachments(&self) -> Vec<Attachment>
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).
Sourcepub fn attachment_data(&self, i: usize) -> Result<Vec<u8>>
pub fn attachment_data(&self, i: usize) -> Result<Vec<u8>>
The bytes of attachment i of Document::attachments.
Sourcepub fn layers(&self) -> Vec<Layer>
pub fn layers(&self) -> Vec<Layer>
The optional content groups (“layers”) and whether the default configuration shows each.
Sourcepub fn layer_tree(&self) -> Option<Vec<LayerNode>>
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.
Sourcepub fn set_layers(&mut self, visible: &[bool]) -> Result<()>
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.