Skip to main content

Attachment

Struct Attachment 

Source
pub struct Attachment {
    pub name: String,
    pub bytes: Vec<u8>,
    pub mime_type: Option<String>,
    pub modified: Option<String>,
    pub annotation_page: Option<usize>,
    pub annotation_rect: Option<[f32; 4]>,
    pub annotation_icon: Option<String>,
    pub af_relationship: Option<AfRelationship>,
}
Expand description

One file to embed inside the PDF.

name is the user-visible file name (used for both /F PDFDocEncoded and /UF UTF-16BE entries per §7.11.3 Table 44). bytes is the raw payload — the writer FlateDecode-compresses it when that shrinks the stream, otherwise stores cleartext.

mime_type populates the embedded-file stream’s /Subtype per §7.11.4 Table 45. It must be a MIME type per RFC 2046 (e.g. "text/plain", "image/png"); the writer encodes the / as #2F in the PDF Name per §7.3.5. When None, the /Subtype entry is omitted.

modified is the embedded file’s last-modified date in PDF date format D:YYYYMMDDHHmmSSOHH'mm' per §7.9.4. When None, the writer omits the /Params /ModDate entry.

annotation_page and annotation_rect are paired: when both are Some, the writer emits a /FileAttachment annotation on the specified page (per §12.5.6.15) referencing this filespec. When either is None, no annotation is created (the file is still embedded

  • reachable via the /Names → /EmbeddedFiles name tree).

Fields§

§name: String

File name shown to the user (e.g. "notes.txt").

§bytes: Vec<u8>

Raw file bytes — the writer compresses these via FlateDecode when that shrinks the result.

§mime_type: Option<String>

MIME type per RFC 2046; lowered to the embedded-file stream’s /Subtype Name (§7.11.4 Table 45). None ⇒ entry omitted.

§modified: Option<String>

Last-modified date, raw PDF date string (§7.9.4). None/Params /ModDate omitted.

§annotation_page: Option<usize>

Optional /FileAttachment annotation page (0-based index into scene.pages). Pairs with Self::annotation_rect.

§annotation_rect: Option<[f32; 4]>

Optional /FileAttachment annotation rectangle in default user space (PDF coordinates, origin bottom-left). Pairs with Self::annotation_page.

§annotation_icon: Option<String>

Optional /FileAttachment icon name per §12.5.6.15 Table 187: Graph, Paperclip, PushPin, Tag. Defaults to PushPin.

§af_relationship: Option<AfRelationship>

Optional /AFRelationship per ISO 32000-2 §7.11.3 Table 44. When Some, the writer emits the matching /AFRelationship Name on this attachment’s filespec and includes the filespec reference in the catalog /AF array (§14.13.3). When the attachment also carries an annotation, the page-level /AF array is populated too (§14.13.4). None ⇒ the filespec carries no /AFRelationship and no /AF arrays are emitted — preserving the round-33 byte shape exactly.

Implementations§

Source§

impl Attachment

Source

pub fn new(name: impl Into<String>, bytes: impl Into<Vec<u8>>) -> Self

Convenience constructor — only the required fields. mime_type / modified / annotation pieces / af_relationship are all None.

Source

pub fn with_mime_type(self, mime: impl Into<String>) -> Self

Builder-style MIME type setter.

Source

pub fn with_modified(self, date: impl Into<String>) -> Self

Builder-style modification-date setter (raw PDF date string).

Source

pub fn with_annotation(self, page_index: usize, rect: [f32; 4]) -> Self

Builder-style FileAttachment annotation setter.

Source

pub fn with_af_relationship(self, rel: AfRelationship) -> Self

Builder-style /AFRelationship setter (ISO 32000-2 §7.11.3 Table 44 + §14.13). Calling this both stamps /AFRelationship on the filespec dict and opts the attachment into the catalog (and, if with_annotation is also set, page) /AF arrays. PDF 1.7 consumers ignore both entries, so the same writer call also produces PDF/A-3-shaped output for downstream consumers that understand it.

Trait Implementations§

Source§

impl Clone for Attachment

Source§

fn clone(&self) -> Attachment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Attachment

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V