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 → /EmbeddedFilesname tree).
Fields§
§name: StringFile 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
impl Attachment
Sourcepub fn new(name: impl Into<String>, bytes: impl Into<Vec<u8>>) -> Self
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.
Sourcepub fn with_mime_type(self, mime: impl Into<String>) -> Self
pub fn with_mime_type(self, mime: impl Into<String>) -> Self
Builder-style MIME type setter.
Sourcepub fn with_modified(self, date: impl Into<String>) -> Self
pub fn with_modified(self, date: impl Into<String>) -> Self
Builder-style modification-date setter (raw PDF date string).
Sourcepub fn with_annotation(self, page_index: usize, rect: [f32; 4]) -> Self
pub fn with_annotation(self, page_index: usize, rect: [f32; 4]) -> Self
Builder-style FileAttachment annotation setter.
Sourcepub fn with_af_relationship(self, rel: AfRelationship) -> Self
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
impl Clone for Attachment
Source§fn clone(&self) -> Attachment
fn clone(&self) -> Attachment
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more