Skip to main content

Document

Struct Document 

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

a PDF document being built: its pages, fonts, images, outlines and information

Implementations§

Source§

impl Document

Source

pub fn new() -> Document

Source

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)

Source

pub fn page_count(&self) -> usize

Source

pub fn page_size(&self, page: PageId) -> Option<(f64, f64)>

width and height in points

Source

pub fn canvas(&mut self, page: PageId, origin: Origin) -> Canvas<'_>

drawing on a page (panics for a page this document does not have)

Source

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)

Source

pub fn font_metrics(&self, font: FontId) -> Option<FontMetrics>

Source

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

Source

pub fn text_width(&self, fonts: &[FontId], size: f64, text: &str) -> f64

the advance of one shaped line at size points

Source

pub fn add_image(&mut self, img: Image) -> ImageId

Source

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

Source

pub fn set_outline_open(&mut self, item: OutlineId, open: bool)

Source

pub fn set_info(&mut self, info: Info)

Source

pub fn set_language(&mut self, lang: &str)

the document’s language (BCP 47, e.g. “de-DE”)

Source

pub fn set_compression(&mut self, level: u8)

DEFLATE level 0 (streams uncompressed, for reading the file) to 9; default 6

Source

pub fn set_encryption(&mut self, e: Option<Encryption>)

encrypt the file (None: not, the default); see Encryption

Source

pub fn write(&self) -> Result<Vec<u8>, Error>

the PDF file

Trait Implementations§

Source§

impl Default for Document

Source§

fn default() -> Document

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Document

§

impl !UnwindSafe for Document

§

impl Forget for Document

§

impl Freeze for Document
where *const u8 is !null: Freeze, PhantomData<PageData>: Freeze, PhantomData<FontData>: Freeze, PhantomData<Image>: Freeze, PhantomData<(u16, u16)>: Freeze, *const LeafNode<(u16, u16), usize> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<((u16, u16), usize)>>: Freeze, PhantomData<Vec<u8>>: Freeze, *const LeafNode<Vec<u8>, usize> is !null: Freeze, PhantomData<Box<(Vec<u8>, usize)>>: Freeze, PhantomData<(usize, [f64; 4])>: Freeze, *const LeafNode<(usize, Vec<u8>), usize> is !null: Freeze, PhantomData<Box<((usize, Vec<u8>), usize)>>: Freeze, PhantomData<OutlineItem>: Freeze, PhantomData<u8>: Freeze, PhantomData<FieldData>: Freeze, *const LeafNode<String, usize> is !null: Freeze, PhantomData<Box<(String, usize)>>: Freeze, &'static str: Freeze,

§

impl Move for Document

§

impl Send for Document
where RawVecInner: Send, NodeRef<Owned, usize, SetValZST, LeafOrInternal>: Send, BoxRaw<(usize, SetValZST)>: Send, Arc<SharedFontRepr>: Send, Arc<VariedInstance>: Send, NodeRef<Owned, u16, Option<String>, LeafOrInternal>: Send, BoxRaw<(u16, Option<String>)>: Send, NodeRef<Owned, (u16, u16), usize, LeafOrInternal>: Send, BoxRaw<((u16, u16), usize)>: Send, NodeRef<Owned, Vec<u8>, usize, LeafOrInternal>: Send, BoxRaw<(Vec<u8>, usize)>: Send, NodeRef<Owned, (usize, Vec<u8>), usize, LeafOrInternal>: Send, BoxRaw<((usize, Vec<u8>), usize)>: Send, NodeRef<Owned, String, usize, LeafOrInternal>: Send, BoxRaw<(String, usize)>: Send, &'static str: Send,

§

impl Sync for Document
where RawVecInner: Sync, NodeRef<Owned, usize, SetValZST, LeafOrInternal>: Sync, BoxRaw<(usize, SetValZST)>: Sync, Arc<SharedFontRepr>: Sync, Arc<VariedInstance>: Sync, NodeRef<Owned, u16, Option<String>, LeafOrInternal>: Sync, BoxRaw<(u16, Option<String>)>: Sync, NodeRef<Owned, (u16, u16), usize, LeafOrInternal>: Sync, BoxRaw<((u16, u16), usize)>: Sync, NodeRef<Owned, Vec<u8>, usize, LeafOrInternal>: Sync, BoxRaw<(Vec<u8>, usize)>: Sync, NodeRef<Owned, (usize, Vec<u8>), usize, LeafOrInternal>: Sync, BoxRaw<((usize, Vec<u8>), usize)>: Sync, NodeRef<Owned, String, usize, LeafOrInternal>: Sync, BoxRaw<(String, usize)>: Sync,

§

impl Unpin for Document
where *const u8 is !null: Unpin, *const LeafNode<usize, SetValZST> is !null: Unpin, Box<(usize, SetValZST)>: Unpin, Arc<SharedFontRepr>: Unpin, Arc<VariedInstance>: Unpin, *const LeafNode<u16, Option<String>> is !null: Unpin, Box<(u16, Option<String>)>: Unpin, *const LeafNode<(u16, u16), usize> is !null: Unpin, Box<((u16, u16), usize)>: Unpin, *const LeafNode<Vec<u8>, usize> is !null: Unpin, Box<(Vec<u8>, usize)>: Unpin, *const LeafNode<(usize, Vec<u8>), usize> is !null: Unpin, Box<((usize, Vec<u8>), usize)>: Unpin, *const LeafNode<String, usize> is !null: Unpin, Box<(String, usize)>: Unpin, &'static str: Unpin,

§

impl UnsafeUnpin for Document

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> 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> ErasedDestructor for T
where T: 'static,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.