Skip to main content

Writer

Struct Writer 

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

Accumulates numbered objects and serializes them into a complete PDF file. Objects are numbered in the order they are first claimed (put, put_stream, or reserve), starting at 1, generation 0.

Implementations§

Source§

impl Writer

Source

pub fn new(options: WriteOptions) -> Writer

Creates a writer with the given options.

Source

pub fn reserve(&mut self) -> ObjRef

Claims an object number now to be filled later — for cycles like the page tree, where children point at a parent not yet built.

Source

pub fn put(&mut self, obj: Object) -> ObjRef

Adds a complete object and returns its reference.

Source

pub fn put_stream(&mut self, dict: Dict, data: Vec<u8>) -> ObjRef

Adds a stream object. /Length is computed on emission; when WriteOptions::compress is set and dict names no /Filter, the data is Flate-compressed and /Filter /FlateDecode added.

Source

pub fn put_stream_raw(&mut self, dict: Dict, data: Vec<u8>) -> ObjRef

Adds a stream object without touching its filters — for data that is already encoded (e.g. a JPEG passed through as /DCTDecode, with /Filter set by the caller). /Length is still computed.

Source

pub fn fill(&mut self, r: ObjRef, obj: Object) -> Result<()>

Fills a previously reserved object.

Source

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

Registers the document information dictionary for the trailer.

Source

pub fn finish(self, root: ObjRef) -> Result<Vec<u8>>

Serializes everything into a complete PDF file: header with binary comment, all objects (packed into object streams where options allow), the cross-reference, and the trailer with root, the registered info dictionary, and a /ID pair derived from a SHA-256 of the emitted body.

Source

pub fn finish_into(self, root: ObjRef, out: impl Write) -> Result<()>

Writer::finish streaming into a std::io::Write: the same bytes, delivered in bounded chunks, so the whole file never sits in one buffer. Unlike finish, an error can leave a prefix of the file already written to out. No flush is performed.

Source

pub async fn finish_into_with<S: AsyncByteSink>( self, root: ObjRef, sink: S, ) -> Result<S>

Writer::finish streaming into any AsyncByteSink — the asynchronous twin of Writer::finish_into, and the one emission implementation all three finishes drive. Bytes arrive in bounded chunks (per header, object and cross-reference section; a stream’s data is its own chunk). An error can leave a prefix of the file already written. Hands the sink back unflushed.

Trait Implementations§

Source§

impl Debug for Writer

Source§

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

Formats the value using the given formatter. 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> 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, <T as TryFrom<U>>::Error>

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.