Skip to content

Commit

Permalink
Add file ID
Browse files Browse the repository at this point in the history
  • Loading branch information
reknih committed Sep 30, 2023
1 parent d052a79 commit c01bbc4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub struct PdfWriter {
offsets: Vec<(Ref, usize)>,
catalog_id: Option<Ref>,
info_id: Option<Ref>,
file_id: Option<(Vec<u8>, Vec<u8>)>,
}

/// Core methods.
Expand All @@ -202,6 +203,7 @@ impl PdfWriter {
offsets: vec![],
catalog_id: None,
info_id: None,
file_id: None,
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<u8>, Vec<u8>)) {
self.file_id = Some(id);
}

/// Start writing a page tree.
pub fn pages(&mut self, id: Ref) -> Pages<'_> {
self.indirect(id).start()
Expand Down

0 comments on commit c01bbc4

Please sign in to comment.