Skip to content

Commit 45244af

Browse files
authored
Add function to update the binary marker in the header (#38)
1 parent 46afbac commit 45244af

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ impl Pdf {
230230
}
231231
}
232232

233+
/// Set the binary marker in the header of the PDF.
234+
///
235+
/// This can be useful if you want to ensure that your PDF consists of only
236+
/// ASCII characters, as this is not the case by default.
237+
///
238+
/// _Default value_: \x80\x80\x80\x80
239+
pub fn set_binary_marker(&mut self, marker: &[u8; 4]) {
240+
self.chunk.buf[10..14].copy_from_slice(marker);
241+
}
242+
233243
/// Set the PDF version.
234244
///
235245
/// The version is not semantically important to the crate, but must be
@@ -485,4 +495,17 @@ mod tests {
485495
w.indirect(Ref::new(6)).primitive(2);
486496
w.finish();
487497
}
498+
499+
#[test]
500+
fn test_binary_marker() {
501+
let mut w = Pdf::new();
502+
w.set_binary_marker(&[b'A', b'B', b'C', b'D']);
503+
test!(
504+
w.finish(),
505+
b"%PDF-1.7\n%ABCD\n",
506+
b"xref\n0 1\n0000000000 65535 f\r",
507+
b"trailer\n<<\n /Size 1\n>>",
508+
b"startxref\n16\n%%EOF",
509+
);
510+
}
488511
}

0 commit comments

Comments
 (0)