Skip to content

Commit 53dcc39

Browse files
authored
Add associated file typed array writers (#41)
1 parent ca47a55 commit 53dcc39

4 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/annotations.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ impl<'a> Annotation<'a> {
228228
self.pair(Name(b"Parent"), id);
229229
self
230230
}
231+
232+
/// Start writing the `/AF` array to specify the associated files of the
233+
/// annotation. PDF 2.0+ or PDF/A-3.
234+
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
235+
self.insert(Name(b"AF")).array().typed()
236+
}
231237
}
232238

233239
deref!('a, Annotation<'a> => Dict<'a>, dict);

src/files.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ impl<'a> FileSpec<'a> {
5353
/// PDF 1.3+.
5454
///
5555
/// This only sets an embedded file for the `F` attribute corresponding to
56-
/// the [`path`](Self::path) method. You will need to write this dictionary
57-
/// manually if you need to set `UF` which is required in PDF/A-3.
56+
/// the [`path`](Self::path) method. If you want to set the same embedded
57+
/// file for the `UF` attribute, also call [`Self::embedded_file_with_unicode`]
58+
/// instead.
5859
///
5960
/// Note that this key is forbidden in PDF/A-1 and restricted in PDF/A-2 and
6061
/// PDF/A-4.
@@ -63,6 +64,19 @@ impl<'a> FileSpec<'a> {
6364
self
6465
}
6566

67+
/// Write the `/EF` attribute to reference an [embedded file](EmbeddedFile)
68+
/// for the legacy and Unicode-compatible file path. PDF 1.7+.
69+
///
70+
/// Note that this key is forbidden in PDF/A-1 and restricted in PDF/A-2 an
71+
/// PDF/A-4.
72+
pub fn embedded_file_with_unicode(&mut self, id: Ref) -> &mut Self {
73+
self.insert(Name(b"EF"))
74+
.dict()
75+
.pair(Name(b"F"), id)
76+
.pair(Name(b"UF"), id);
77+
self
78+
}
79+
6680
/// How this file relates to the PDF document it is embedded in.
6781
/// PDF/A-3 and PDF/A-4f.
6882
pub fn association_kind(&mut self, kind: AssociationKind) -> &mut Self {

src/structure.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> Catalog<'a> {
147147
}
148148

149149
/// Start writing the `/AF` array to specify the associated files of the
150-
/// document. PDF 2.0+.
150+
/// document. PDF 2.0+ or PDF/A-3.
151151
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
152152
self.insert(Name(b"AF")).array().typed()
153153
}
@@ -495,6 +495,12 @@ impl<'a> StructElement<'a> {
495495
self.dict.pair(Name(b"ActualText"), actual_text);
496496
self
497497
}
498+
499+
/// Start writing the `/AF` array to specify the associated files of the
500+
/// element. PDF 2.0+ or PDF/A-3.
501+
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
502+
self.insert(Name(b"AF")).array().typed()
503+
}
498504
}
499505

500506
deref!('a, StructElement<'a> => Dict<'a>, dict);
@@ -1247,6 +1253,12 @@ impl<'a> Page<'a> {
12471253
self.pair(Name(b"Metadata"), id);
12481254
self
12491255
}
1256+
1257+
/// Start writing the `/AF` array to specify the associated files of the
1258+
/// page. PDF 2.0+ or PDF/A-3.
1259+
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
1260+
self.insert(Name(b"AF")).array().typed()
1261+
}
12501262
}
12511263

12521264
deref!('a, Page<'a> => Dict<'a>, dict);

src/xobject.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ impl<'a> ImageXObject<'a> {
155155
self.pair(Name(b"Metadata"), id);
156156
self
157157
}
158+
159+
/// Start writing the `/AF` array to specify the associated files of the
160+
/// image. PDF 2.0+ or PDF/A-3.
161+
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
162+
self.insert(Name(b"AF")).array().typed()
163+
}
158164
}
159165

160166
deref!('a, ImageXObject<'a> => Stream<'a>, stream);
@@ -263,6 +269,12 @@ impl<'a> FormXObject<'a> {
263269
self.pair(Name(b"LastModified"), last_modified);
264270
self
265271
}
272+
273+
/// Start writing the `/AF` array to specify the associated files of the
274+
/// Form XObject. PDF 2.0+ or PDF/A-3.
275+
pub fn associated_files(&mut self) -> TypedArray<'_, FileSpec> {
276+
self.insert(Name(b"AF")).array().typed()
277+
}
266278
}
267279

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

0 commit comments

Comments
 (0)