From c01bbc4b5cd043771cabeb719debe0e9de108bd1 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sat, 30 Sep 2023 13:14:13 +0200 Subject: [PATCH] Add file ID --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f10ad06..8dc1802 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,6 +182,7 @@ pub struct PdfWriter { offsets: Vec<(Ref, usize)>, catalog_id: Option, info_id: Option, + file_id: Option<(Vec, Vec)>, } /// Core methods. @@ -202,6 +203,7 @@ impl PdfWriter { offsets: vec![], catalog_id: None, info_id: None, + file_id: None, } } @@ -289,6 +291,12 @@ impl PdfWriter { trailer.pair(Name(b"Info"), info_id); } + if let Some(file_id) = self.file_id { + let mut ids = trailer.insert(Name(b"ID")).array(); + ids.item(Str(&file_id.0)); + ids.item(Str(&file_id.1)); + } + trailer.finish(); // Write where the cross-reference table starts. @@ -384,6 +392,16 @@ impl PdfWriter { self.indirect(id).start() } + /// Set the file identifier for the document. + /// + /// The file identifier is a pair of two byte strings that shall be used to + /// uniquely identify a particular file. The first string should always stay + /// the same for a document, the second should change for each revision. It + /// is optional, but recommended. PDF 1.1+. + pub fn file_id(&mut self, id: (Vec, Vec)) { + self.file_id = Some(id); + } + /// Start writing a page tree. pub fn pages(&mut self, id: Ref) -> Pages<'_> { self.indirect(id).start()