Skip to main content

PdfWriter

Struct PdfWriter 

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

PDF document writer.

Builds a complete PDF document with pages, fonts, and content.

Implementations§

Source§

impl PdfWriter

Source

pub fn new() -> Self

Create a new PDF writer with default config.

Source

pub fn with_config(config: PdfWriterConfig) -> Self

Create a PDF writer with custom config.

Source

pub fn set_outline(&mut self, outline: OutlineBuilder)

Attach a document outline (bookmarks) to be emitted during PdfWriter::finish. Replaces any previously-set outline.

Source

pub fn set_page_labels(&mut self, labels: PageLabelsBuilder)

Attach a /PageLabels number-tree (Roman numeral preface → Arabic body etc.) to be emitted during finish.

Source

pub fn register_embedded_font(&mut self, font: EmbeddedFont) -> String

Register an embedded TrueType font for use in content streams.

Returns the resource name (e.g. "EF1") that add_embedded_text should use. The font is consumed; finish() emits its five PDF objects (Type 0 / CIDFontType2 / FontDescriptor / FontFile2 stream / ToUnicode CMap stream — ISO 32000-1 §9.6.4 / §9.7.4 / §9.8 / §9.9 / §9.10.2).

The font’s display name (used in PostScript/BaseFont fields) is taken from EmbeddedFont::name. Callers wanting a stable subset tag should track the resource name they get back and reuse it.

Source

pub fn register_embedded_font_as( &mut self, user_name: impl Into<String>, font: EmbeddedFont, ) -> String

Register an embedded TrueType font under a user-visible name (e.g. "NotoSansCJKtc"). The name is what callers pass to FluentPageBuilder::font(name, size) / FontSpec::name; when a ContentElement::Text is dispatched, the PageBuilder looks up this map and routes matching elements through add_embedded_text (hex-encoded Type-0 emission) instead of the base-14 map_font_name fallback that silently collapses unknown names to Helvetica.

Returns the EFn resource name for callers that want to mix low-level add_embedded_text calls with the high-level path.

Source

pub fn add_page(&mut self, width: f32, height: f32) -> PageBuilder<'_>

Add a page with the given dimensions.

Source

pub fn add_letter_page(&mut self) -> PageBuilder<'_>

Add a US Letter sized page (8.5“ x 11“).

Source

pub fn add_a4_page(&mut self) -> PageBuilder<'_>

Add an A4 sized page (210mm x 297mm).

Source

pub fn finish(self) -> Result<Vec<u8>>

Build the complete PDF document.

Source

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

Save the PDF to a file.

Trait Implementations§

Source§

impl Default for PdfWriter

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.
Source§

impl<T> Ungil for T
where T: Send,