pub struct Document { /* private fields */ }Expand description
A PDF being built. See the module documentation.
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(version: &str) -> Result<Document, WriteError>
pub fn new(version: &str) -> Result<Document, WriteError>
Start a document. version is "1.0" to "1.7" ("1.4" for the widest readers).
pub fn page_count(&self) -> usize
Sourcepub fn add_icc_profile(
&mut self,
profile: Vec<u8>,
components: u8,
) -> Result<IccId, WriteError>
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+.
Sourcepub fn add_page(
&mut self,
width_pt: f64,
height_pt: f64,
) -> Result<PageId, WriteError>
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).
Sourcepub fn place_jpeg(
&mut self,
page: PageId,
jpeg: Vec<u8>,
icc: Option<IccId>,
) -> Result<JpegInfo, WriteError>
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.
Sourcepub fn add_jpeg_page(
&mut self,
width_pt: f64,
height_pt: f64,
jpeg: Vec<u8>,
icc: Option<IccId>,
) -> Result<PageId, WriteError>
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.
Sourcepub fn finish(&self) -> Vec<u8> ⓘ
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.
Sourcepub fn try_finish(&self) -> Result<Vec<u8>, WriteError>
pub fn try_finish(&self) -> Result<Vec<u8>, WriteError>
Self::finish returning font subsetting failures as errors.
Sourcepub fn add_font(
&mut self,
bytes: Vec<u8>,
face_index: u32,
) -> Result<FontId, WriteError>
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.
Sourcepub fn measure_text(
&self,
font: FontId,
size_pt: f64,
text: &str,
) -> Result<f64, WriteError>
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.
Sourcepub 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>
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).
Sourcepub fn write_to(&self, path: &Path) -> Result<()>
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§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.