pub struct Document { /* private fields */ }Expand description
a PDF document being built: its pages, fonts, images, outlines and information
Implementations§
Source§impl Document
impl Document
pub fn new() -> Document
Sourcepub fn add_page(&mut self, width: f64, height: f64) -> PageId
pub fn add_page(&mut self, width: f64, height: f64) -> PageId
a new page at the end, width and height in points (clamped to PAGE_MIN .. PAGE_MAX)
pub fn page_count(&self) -> usize
Sourcepub fn canvas(&mut self, page: PageId, origin: Origin) -> Canvas<'_>
pub fn canvas(&mut self, page: PageId, origin: Origin) -> Canvas<'_>
drawing on a page (panics for a page this document does not have)
Sourcepub fn add_font(&mut self, data: Vec<u8>, face: u32) -> Result<FontId, Error>
pub fn add_font(&mut self, data: Vec<u8>, face: u32) -> Result<FontId, Error>
a TrueType or OpenType font (glyf or CFF outlines; face: of a collection, else 0)
pub fn font_metrics(&self, font: FontId) -> Option<FontMetrics>
Sourcepub fn shape(&self, fonts: &[FontId], text: &str) -> Vec<Glyph>
pub fn shape(&self, fonts: &[FontId], text: &str) -> Vec<Glyph>
one line shaped with the fonts (the first, then fallbacks per script run); empty for an unknown font or a line beyond 64 KiB
Sourcepub fn text_width(&self, fonts: &[FontId], size: f64, text: &str) -> f64
pub fn text_width(&self, fonts: &[FontId], size: f64, text: &str) -> f64
the advance of one shaped line at size points
pub fn add_image(&mut self, img: Image) -> ImageId
Sourcepub fn add_outline(
&mut self,
parent: Option<OutlineId>,
title: &str,
dest: Dest,
) -> OutlineId
pub fn add_outline( &mut self, parent: Option<OutlineId>, title: &str, dest: Dest, ) -> OutlineId
an outline item (bookmark) under parent (None: at the top), after its siblings; open
(its children shown) until set_outline_open says otherwise
pub fn set_outline_open(&mut self, item: OutlineId, open: bool)
pub fn set_info(&mut self, info: Info)
Sourcepub fn set_language(&mut self, lang: &str)
pub fn set_language(&mut self, lang: &str)
the document’s language (BCP 47, e.g. “de-DE”)
Sourcepub fn set_compression(&mut self, level: u8)
pub fn set_compression(&mut self, level: u8)
DEFLATE level 0 (streams uncompressed, for reading the file) to 9; default 6
Sourcepub fn set_encryption(&mut self, e: Option<Encryption>)
pub fn set_encryption(&mut self, e: Option<Encryption>)
encrypt the file (None: not, the default); see Encryption