Skip to content

Commit

Permalink
Merge branch 'main' into pdf-a
Browse files Browse the repository at this point in the history
  • Loading branch information
laurmaedje committed Sep 4, 2024
2 parents a8a0e59 + f809ed8 commit 82974dc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Cargo.lock
_things
.DS_Store
.idea/
6 changes: 6 additions & 0 deletions src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ impl Chunk {
.extend(other.offsets.iter().map(|&(id, offset)| (id, base + offset)));
}

/// An iterator over the references of the top-level objects
/// of the chunk, in the order they appear in the chunk.
pub fn refs(&self) -> impl IntoIterator<Item = Ref> + '_ {
self.offsets.iter().map(|&(id, _)| id)
}

/// Renumbers the IDs of indirect objects and all indirect references in the
/// chunk and returns the resulting chunk.
///
Expand Down
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ impl Pdf {
}
}

/// Set the binary marker in the header of the PDF.
///
/// This can be useful if you want to ensure that your PDF consists of only
/// ASCII characters, as this is not the case by default.
///
/// _Default value_: \x80\x80\x80\x80
pub fn set_binary_marker(&mut self, marker: &[u8; 4]) {
self.chunk.buf[10..14].copy_from_slice(marker);
}

/// Set the PDF version.
///
/// The version is not semantically important to the crate, but must be
Expand Down Expand Up @@ -487,4 +497,17 @@ mod tests {
w.indirect(Ref::new(6)).primitive(2);
w.finish();
}

#[test]
fn test_binary_marker() {
let mut w = Pdf::new();
w.set_binary_marker(&[b'A', b'B', b'C', b'D']);
test!(
w.finish(),
b"%PDF-1.7\n%ABCD\n",
b"xref\n0 1\n0000000000 65535 f\r",
b"trailer\n<<\n /Size 1\n>>",
b"startxref\n16\n%%EOF",
);
}
}
6 changes: 6 additions & 0 deletions src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ impl<'a> Catalog<'a> {
pub fn output_intents(&mut self) -> TypedArray<'_, OutputIntent> {
self.insert(Name(b"OutputIntents")).array().typed()
}

/// Start writing the `/AF` array to specify the associated files of the
/// document. PDF 2.0+.
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
self.insert(Name(b"AF")).array().typed()
}
}

deref!('a, Catalog<'a> => Dict<'a>, dict);
Expand Down

0 comments on commit 82974dc

Please sign in to comment.