Skip to content

Commit

Permalink
Add associated file typed array writers (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
reknih authored Sep 30, 2024
1 parent ca47a55 commit 53dcc39
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ impl<'a> Annotation<'a> {
self.pair(Name(b"Parent"), id);
self
}

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

deref!('a, Annotation<'a> => Dict<'a>, dict);
Expand Down
18 changes: 16 additions & 2 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ impl<'a> FileSpec<'a> {
/// PDF 1.3+.
///
/// This only sets an embedded file for the `F` attribute corresponding to
/// the [`path`](Self::path) method. You will need to write this dictionary
/// manually if you need to set `UF` which is required in PDF/A-3.
/// the [`path`](Self::path) method. If you want to set the same embedded
/// file for the `UF` attribute, also call [`Self::embedded_file_with_unicode`]
/// instead.
///
/// Note that this key is forbidden in PDF/A-1 and restricted in PDF/A-2 and
/// PDF/A-4.
Expand All @@ -63,6 +64,19 @@ impl<'a> FileSpec<'a> {
self
}

/// Write the `/EF` attribute to reference an [embedded file](EmbeddedFile)
/// for the legacy and Unicode-compatible file path. PDF 1.7+.
///
/// Note that this key is forbidden in PDF/A-1 and restricted in PDF/A-2 an
/// PDF/A-4.
pub fn embedded_file_with_unicode(&mut self, id: Ref) -> &mut Self {
self.insert(Name(b"EF"))
.dict()
.pair(Name(b"F"), id)
.pair(Name(b"UF"), id);
self
}

/// How this file relates to the PDF document it is embedded in.
/// PDF/A-3 and PDF/A-4f.
pub fn association_kind(&mut self, kind: AssociationKind) -> &mut Self {
Expand Down
14 changes: 13 additions & 1 deletion src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'a> Catalog<'a> {
}

/// Start writing the `/AF` array to specify the associated files of the
/// document. PDF 2.0+.
/// document. PDF 2.0+ or PDF/A-3.
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
self.insert(Name(b"AF")).array().typed()
}
Expand Down Expand Up @@ -495,6 +495,12 @@ impl<'a> StructElement<'a> {
self.dict.pair(Name(b"ActualText"), actual_text);
self
}

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

deref!('a, StructElement<'a> => Dict<'a>, dict);
Expand Down Expand Up @@ -1247,6 +1253,12 @@ impl<'a> Page<'a> {
self.pair(Name(b"Metadata"), id);
self
}

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

deref!('a, Page<'a> => Dict<'a>, dict);
Expand Down
12 changes: 12 additions & 0 deletions src/xobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ impl<'a> ImageXObject<'a> {
self.pair(Name(b"Metadata"), id);
self
}

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

deref!('a, ImageXObject<'a> => Stream<'a>, stream);
Expand Down Expand Up @@ -263,6 +269,12 @@ impl<'a> FormXObject<'a> {
self.pair(Name(b"LastModified"), last_modified);
self
}

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

deref!('a, FormXObject<'a> => Stream<'a>, stream);
Expand Down

0 comments on commit 53dcc39

Please sign in to comment.