pub fn associate_file_with_document(
dest: &mut EditDoc<'_>,
limits: &Limits,
index: usize,
relationship: Relationship,
) -> Result<bool, Error>Expand description
Associates the attachment at index with the document, by adding it to
the catalog’s /AF.
The attachment stays where it is; this adds a second reference to the same
file specification, which is what makes the file both savable from the
attachments pane and declared as related to the document. relationship
is written onto the specification as /AFRelationship.
Answers false when there is no attachment at index. An attachment
already in the catalog’s /AF has only its relationship updated rather
than being listed twice.
§Errors
Error::NoDestinationCatalog when the document has no catalog.
use std::sync::Arc;
use pdfrum_common::Limits;
use pdfrum_edit::{
AttachmentOptions, EditDoc, Relationship, SaveOptions, add_attachment,
associate_file_with_document, save,
};
use pdfrum_parser::{LoadOptions, load};
let bytes: Arc<[u8]> = Arc::from(&include_bytes!("../tests/files/hello.pdf")[..]);
let doc = load(bytes, &LoadOptions::default())?;
let mut edit = EditDoc::new(&doc);
let limits = Limits::default();
let index = add_attachment(
&mut edit,
&limits,
"invoice.xml",
b"<invoice/>",
&AttachmentOptions::builder().mime_type("text/xml").build(),
)?;
associate_file_with_document(&mut edit, &limits, index, Relationship::Alternative)?;
let mut out = Vec::new();
save(&edit, &SaveOptions::default(), &mut out)?;