pub struct Pdf {
pub metadata: Option<Metadata>,
pub pages: Vec<Page>,
pub outline: Option<Outline>,
pub attachments: Vec<Attachment>,
pub page_labels: Vec<PageLabel>,
pub viewer: Option<Viewer>,
pub options: WriteOptions,
}Expand description
A document under construction. The fields are the composition:
singleton slots are Options, pages keep the order given.
Fields§
§metadata: Option<Metadata>Document information, if any.
pages: Vec<Page>Pages, in reading order.
outline: Option<Outline>Bookmark panel, if any.
attachments: Vec<Attachment>Document-level attachments. Reordered by name, lexicographically
by bytes, at emission — the name-tree keys must be sorted, so the
order given here is not preserved. Duplicate names are an error.
page_labels: Vec<PageLabel>Page-numbering ranges shown in viewer UI as /PageLabels.
Reordered by first_page at emission. Must include a range
starting at page 0 when non-empty; duplicate first_page values
are an error.
viewer: Option<Viewer>Viewer preferences, if any.
options: WriteOptionsFile-emission options.
Implementations§
Source§impl Pdf
impl Pdf
Sourcepub fn to_bytes(self) -> Result<Vec<u8>, Error>
pub fn to_bytes(self) -> Result<Vec<u8>, Error>
Serializes the document to complete PDF file bytes.
Fonts are shared document-wide: each distinct Standard14 face
gets one font object, in first-use order. Images are embedded per
page with no cross-page deduplication — the same raster drawn on
two pages is stored twice. Groups follow the same rule: a canvas
registered with Canvas::group on two different pages produces two
Form XObjects — cross-page group sharing is deferred.
Sourcepub fn write_into(self, out: impl Write) -> Result<(), Error>
pub fn write_into(self, out: impl Write) -> Result<(), Error>
Pdf::to_bytes streaming into a std::io::Write: the same
bytes, delivered in bounded chunks instead of one buffer. Unlike
to_bytes, an error can leave a prefix of the file already written
to out. No flush is performed.
Sourcepub async fn write_into_with<S>(self, sink: S) -> Result<S, Error>where
S: AsyncByteSink,
pub async fn write_into_with<S>(self, sink: S) -> Result<S, Error>where
S: AsyncByteSink,
Pdf::to_bytes streaming into any AsyncByteSink — the
asynchronous twin of Pdf::write_into. An error can leave a
prefix of the file already written. Hands the sink back unflushed.