Skip to main content

DocumentBuilder

Struct DocumentBuilder 

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

Builds a new PDF 2.0 file.

Obtained from Document::new or DocumentBuilder::new; the catalog (object 1) and the page tree root (object 2) exist from the start.

Implementations§

Source§

impl DocumentBuilder

Source

pub fn new() -> Self

A new, empty document.

Source

pub fn add_object(&mut self, object: Object) -> u32

Add an object and return the number it was assigned.

Source

pub fn add_page(&mut self, media_box: Rect, content: impl Into<Vec<u8>>) -> u32

Append a page with content as its content stream.

Every page gets /Resources << /Font << /F1 … >> >> pointing at one shared Helvetica font, so written content streams that use /F1 are immediately extractable.

Source

pub fn page_count(&self) -> usize

Number of pages appended so far.

Source

pub fn set_metadata(&mut self, xmp: impl Into<Vec<u8>>)

Replace the XMP metadata packet written into the catalog.

Source

pub fn objects(&self) -> impl Iterator<Item = (u32, &Object)>

Iterate over the objects collected so far, in object-number order.

Source

pub fn save(&self) -> Result<Vec<u8>>

Serialize the document as a PDF 2.0 file.

Source

pub fn save_to_path(&self, path: impl AsRef<Path>) -> Result<()>

Write the document to a file.

Trait Implementations§

Source§

impl Clone for DocumentBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DocumentBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DocumentBuilder

Source§

fn default() -> Self

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

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.