Skip to content

Commit c01bbc4

Browse files
committed
Add file ID
1 parent d052a79 commit c01bbc4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ pub struct PdfWriter {
182182
offsets: Vec<(Ref, usize)>,
183183
catalog_id: Option<Ref>,
184184
info_id: Option<Ref>,
185+
file_id: Option<(Vec<u8>, Vec<u8>)>,
185186
}
186187

187188
/// Core methods.
@@ -202,6 +203,7 @@ impl PdfWriter {
202203
offsets: vec![],
203204
catalog_id: None,
204205
info_id: None,
206+
file_id: None,
205207
}
206208
}
207209

@@ -289,6 +291,12 @@ impl PdfWriter {
289291
trailer.pair(Name(b"Info"), info_id);
290292
}
291293

294+
if let Some(file_id) = self.file_id {
295+
let mut ids = trailer.insert(Name(b"ID")).array();
296+
ids.item(Str(&file_id.0));
297+
ids.item(Str(&file_id.1));
298+
}
299+
292300
trailer.finish();
293301

294302
// Write where the cross-reference table starts.
@@ -384,6 +392,16 @@ impl PdfWriter {
384392
self.indirect(id).start()
385393
}
386394

395+
/// Set the file identifier for the document.
396+
///
397+
/// The file identifier is a pair of two byte strings that shall be used to
398+
/// uniquely identify a particular file. The first string should always stay
399+
/// the same for a document, the second should change for each revision. It
400+
/// is optional, but recommended. PDF 1.1+.
401+
pub fn file_id(&mut self, id: (Vec<u8>, Vec<u8>)) {
402+
self.file_id = Some(id);
403+
}
404+
387405
/// Start writing a page tree.
388406
pub fn pages(&mut self, id: Ref) -> Pages<'_> {
389407
self.indirect(id).start()

0 commit comments

Comments
 (0)