Skip to main content

Pdf

Struct Pdf 

Source
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: WriteOptions

File-emission options.

Implementations§

Source§

impl Pdf

Source

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

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.

Source

pub fn write_into(self, out: impl Write) -> Result<()>

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.

Source

pub async fn write_into_with<S: AsyncByteSink>(self, sink: S) -> Result<S>

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.

Source

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

Serializes and writes the document to path.

Trait Implementations§

Source§

impl Debug for Pdf

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Pdf

Source§

fn default() -> Pdf

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Pdf

§

impl !Sync for Pdf

§

impl !UnwindSafe for Pdf

§

impl Freeze for Pdf

§

impl Send for Pdf

§

impl Unpin for Pdf

§

impl UnsafeUnpin for Pdf

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.