Skip to main content

Document

Struct Document 

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

A PDF being built. See the module documentation.

Implementations§

Source§

impl Document

Source

pub fn new(version: &str) -> Result<Document, WriteError>

Start a document. version is "1.0" to "1.7" ("1.4" for the widest readers).

Source

pub fn page_count(&self) -> usize

Source

pub fn add_icc_profile( &mut self, profile: Vec<u8>, components: u8, ) -> Result<IccId, WriteError>

Register an ICC profile (components 1 or 3) to colour-tag JPEGs. Needs PDF 1.3+.

Source

pub fn add_page( &mut self, width_pt: f64, height_pt: f64, ) -> Result<PageId, WriteError>

Append an empty page of width_pt x height_pt (1/72 inch).

Source

pub fn place_jpeg( &mut self, page: PageId, jpeg: Vec<u8>, icc: Option<IccId>, ) -> Result<JpegInfo, WriteError>

Draw jpeg over the whole of page (q w 0 0 h 0 0 cm /Im0 Do Q). icc tags it with a profile whose component count equals the JPEG’s; None uses DeviceRGB or DeviceGray.

Source

pub fn add_jpeg_page( &mut self, width_pt: f64, height_pt: f64, jpeg: Vec<u8>, icc: Option<IccId>, ) -> Result<PageId, WriteError>

Self::add_page then Self::place_jpeg. On an error no page is added.

Source

pub fn finish(&self) -> Vec<u8> ⓘ

The finished file. A document with no pages has an empty page tree.

§Panics

Only if a font that Self::add_font accepted cannot be subset (a damaged table the subsetter rejects); use Self::try_finish to get that as an error. A document without text cannot panic.

Source

pub fn try_finish(&self) -> Result<Vec<u8>, WriteError>

Self::finish returning font subsetting failures as errors.

Source

pub fn add_font( &mut self, bytes: Vec<u8>, face_index: u32, ) -> Result<FontId, WriteError>

Register a TrueType font for Self::draw_text. face_index is 0 for a single-face file. Refused when the font does not parse or its fsType forbids embedding or subsetting. Needs feature fonts.

Source

pub fn measure_text( &self, font: FontId, size_pt: f64, text: &str, ) -> Result<f64, WriteError>

Width of text in points at size_pt: the sum of the font’s advances (no kerning), for right-aligning or centring before Self::draw_text. Refuses a missing glyph.

Source

pub fn draw_text( &mut self, page: PageId, font: FontId, size_pt: f64, x_pt: f64, y_pt: f64, rgb: Option<[f64; 3]>, text: &str, ) -> Result<(), WriteError>

Draw text on page with its baseline starting at (x_pt, y_pt) from the page’s bottom-left, size_pt high. rgb is 0.0 to 1.0 per channel (None leaves the default black). One call is one run: no wrapping, shaping or kerning. Every character needs a glyph in the font (WriteError::MissingGlyph otherwise, nothing is drawn).

Source

pub fn write_to(&self, path: &Path) -> Result<()>

Write Self::finish to path through crate::commit::write_atomic (temp sibling, flush, rename, directory sync): the one documented way to put a new file on disk. Path authorization is the caller’s job.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

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.