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
impl Writer
Sourcepub fn new(options: WriteOptions) -> Writer
pub fn new(options: WriteOptions) -> Writer
Creates a writer with the given options.
Sourcepub fn reserve(&mut self) -> ObjRef
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.
Sourcepub fn put_stream(&mut self, dict: Dict, data: Vec<u8>) -> ObjRef
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.
Sourcepub fn put_stream_raw(&mut self, dict: Dict, data: Vec<u8>) -> ObjRef
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.
Sourcepub fn fill(&mut self, r: ObjRef, obj: Object) -> Result<()>
pub fn fill(&mut self, r: ObjRef, obj: Object) -> Result<()>
Fills a previously reserved object.
Sourcepub fn set_info(&mut self, info: ObjRef)
pub fn set_info(&mut self, info: ObjRef)
Registers the document information dictionary for the trailer.
Sourcepub fn finish(self, root: ObjRef) -> Result<Vec<u8>>
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.
Sourcepub fn finish_into(self, root: ObjRef, out: impl Write) -> Result<()>
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.
Sourcepub async fn finish_into_with<S: AsyncByteSink>(
self,
root: ObjRef,
sink: S,
) -> Result<S>
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.