blitz-pdf 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +300 -10
  2. package/THIRD_PARTY_NOTICES.md +4 -2
  3. package/dist/browser.d.ts +1 -1
  4. package/dist/browser.d.ts.map +1 -1
  5. package/dist/document-options.d.ts +36 -0
  6. package/dist/document-options.d.ts.map +1 -0
  7. package/dist/document-options.js +236 -0
  8. package/dist/document-options.js.map +1 -0
  9. package/dist/node.d.ts +1 -1
  10. package/dist/node.d.ts.map +1 -1
  11. package/dist/options.d.ts +35 -1
  12. package/dist/options.d.ts.map +1 -1
  13. package/dist/options.js +21 -14
  14. package/dist/options.js.map +1 -1
  15. package/dist/types.d.ts +71 -1
  16. package/dist/types.d.ts.map +1 -1
  17. package/dist/validation.d.ts +2 -0
  18. package/dist/validation.d.ts.map +1 -0
  19. package/dist/validation.js +7 -0
  20. package/dist/validation.js.map +1 -0
  21. package/examples/zugferd.mjs +41 -0
  22. package/licenses/RUST_DEPENDENCIES.txt +27 -0
  23. package/package.json +3 -2
  24. package/src/browser.ts +1 -1
  25. package/src/document-options.ts +218 -0
  26. package/src/node.ts +1 -1
  27. package/src/options.ts +18 -13
  28. package/src/types.ts +76 -1
  29. package/src/validation.ts +6 -0
  30. package/vendor/README.md +27 -2
  31. package/vendor/krilla/.cargo-ok +1 -0
  32. package/vendor/krilla/.cargo_vcs_info.json +6 -0
  33. package/vendor/krilla/Cargo.lock +1357 -0
  34. package/vendor/krilla/Cargo.toml +165 -0
  35. package/vendor/krilla/LICENSE_APACHE +202 -0
  36. package/vendor/krilla/LICENSE_MIT +21 -0
  37. package/vendor/krilla/README.md +156 -0
  38. package/vendor/krilla/examples/basic.rs +117 -0
  39. package/vendor/krilla/examples/empty_document.rs +25 -0
  40. package/vendor/krilla/examples/parley.rs +174 -0
  41. package/vendor/krilla/examples/simple_text.rs +118 -0
  42. package/vendor/krilla/examples/stream_builder.rs +93 -0
  43. package/vendor/krilla/icc/LICENSE +116 -0
  44. package/vendor/krilla/icc/README.md +1 -0
  45. package/vendor/krilla/icc/sGrey-v2-magic.icc +0 -0
  46. package/vendor/krilla/icc/sGrey-v4.icc +0 -0
  47. package/vendor/krilla/icc/sRGB-v2-magic.icc +0 -0
  48. package/vendor/krilla/icc/sRGB-v4.icc +0 -0
  49. package/vendor/krilla/src/chunk_container.rs +503 -0
  50. package/vendor/krilla/src/configure/PDF_A1.md +227 -0
  51. package/vendor/krilla/src/configure/PDF_A2.md +269 -0
  52. package/vendor/krilla/src/configure/PDF_A3.md +31 -0
  53. package/vendor/krilla/src/configure/PDF_A4.md +211 -0
  54. package/vendor/krilla/src/configure/PDF_UA1.md +202 -0
  55. package/vendor/krilla/src/configure/README.md +23 -0
  56. package/vendor/krilla/src/configure/mod.rs +197 -0
  57. package/vendor/krilla/src/configure/validate.rs +1244 -0
  58. package/vendor/krilla/src/configure/version.rs +134 -0
  59. package/vendor/krilla/src/content.rs +1352 -0
  60. package/vendor/krilla/src/data.rs +49 -0
  61. package/vendor/krilla/src/document.rs +156 -0
  62. package/vendor/krilla/src/error.rs +170 -0
  63. package/vendor/krilla/src/geom.rs +341 -0
  64. package/vendor/krilla/src/graphics/blend.rs +46 -0
  65. package/vendor/krilla/src/graphics/color.rs +552 -0
  66. package/vendor/krilla/src/graphics/graphic.rs +30 -0
  67. package/vendor/krilla/src/graphics/graphics_state.rs +251 -0
  68. package/vendor/krilla/src/graphics/icc.rs +218 -0
  69. package/vendor/krilla/src/graphics/image.rs +835 -0
  70. package/vendor/krilla/src/graphics/mask.rs +128 -0
  71. package/vendor/krilla/src/graphics/mod.rs +14 -0
  72. package/vendor/krilla/src/graphics/paint.rs +434 -0
  73. package/vendor/krilla/src/graphics/separation.rs +86 -0
  74. package/vendor/krilla/src/graphics/shading_function.rs +865 -0
  75. package/vendor/krilla/src/graphics/shading_pattern.rs +60 -0
  76. package/vendor/krilla/src/graphics/tiling_pattern.rs +119 -0
  77. package/vendor/krilla/src/graphics/xobject.rs +150 -0
  78. package/vendor/krilla/src/interactive/action.rs +68 -0
  79. package/vendor/krilla/src/interactive/annotation.rs +283 -0
  80. package/vendor/krilla/src/interactive/destination.rs +289 -0
  81. package/vendor/krilla/src/interactive/mod.rs +3 -0
  82. package/vendor/krilla/src/interchange/embed.rs +240 -0
  83. package/vendor/krilla/src/interchange/metadata.rs +564 -0
  84. package/vendor/krilla/src/interchange/mod.rs +4 -0
  85. package/vendor/krilla/src/interchange/outline.rs +263 -0
  86. package/vendor/krilla/src/interchange/tagging/fmt.rs +733 -0
  87. package/vendor/krilla/src/interchange/tagging/generate.toml +474 -0
  88. package/vendor/krilla/src/interchange/tagging/generated.rs +4754 -0
  89. package/vendor/krilla/src/interchange/tagging/mod.rs +1324 -0
  90. package/vendor/krilla/src/interchange/tagging/tag.rs +686 -0
  91. package/vendor/krilla/src/lib.rs +179 -0
  92. package/vendor/krilla/src/num.rs +26 -0
  93. package/vendor/krilla/src/page.rs +612 -0
  94. package/vendor/krilla/src/pdf.rs +313 -0
  95. package/vendor/krilla/src/resource.rs +436 -0
  96. package/vendor/krilla/src/serialize.rs +1101 -0
  97. package/vendor/krilla/src/stream.rs +368 -0
  98. package/vendor/krilla/src/surface.rs +664 -0
  99. package/vendor/krilla/src/text/cid.rs +488 -0
  100. package/vendor/krilla/src/text/font.rs +351 -0
  101. package/vendor/krilla/src/text/glyph/bitmap.rs +81 -0
  102. package/vendor/krilla/src/text/glyph/colr.rs +581 -0
  103. package/vendor/krilla/src/text/glyph/mod.rs +205 -0
  104. package/vendor/krilla/src/text/glyph/outline.rs +72 -0
  105. package/vendor/krilla/src/text/glyph/svg.rs +34 -0
  106. package/vendor/krilla/src/text/group.rs +463 -0
  107. package/vendor/krilla/src/text/mod.rs +232 -0
  108. package/vendor/krilla/src/text/shape.rs +102 -0
  109. package/vendor/krilla/src/text/type3.rs +514 -0
  110. package/vendor/krilla/src/util.rs +286 -0
  111. package/vendor/stylo/properties/longhands.toml +0 -1
  112. package/vendor/stylo/stylesheets/rule_parser.rs +1 -1
  113. package/wasm/blitz_pdf.js +10 -5
  114. package/wasm/blitz_pdf_bg.wasm +0 -0
@@ -0,0 +1,564 @@
1
+ //! Setting document metadata.
2
+ //!
3
+ //! PDF allows for the inclusion of metadata in a PDF document. To do so in krilla,
4
+ //! you can simply create a [`Metadata`] object, set the data, and then include it
5
+ //! in the document via [`Document::set_metadata`].
6
+ //!
7
+ //! [`Document::set_metadata`]: crate::document::Document::set_metadata
8
+ use pdf_writer::{Finish, Pdf, Ref, TextStr};
9
+ use std::cell::LazyCell;
10
+ use xmp_writer::pdfa::PdfAExtSchemasWriter;
11
+ use xmp_writer::{CustomNamespace, LangId, Namespace, Timezone, XmpWriter};
12
+
13
+ use crate::configure::{Configuration, PdfVersion, ValidationError};
14
+ use crate::serialize::SerializeContext;
15
+
16
+ /// Metadata for a PDF document.
17
+ #[derive(Default, Clone, Debug)]
18
+ pub struct Metadata {
19
+ pub(crate) title: Option<String>,
20
+ pub(crate) description: Option<String>,
21
+ pub(crate) creator: Option<String>,
22
+ pub(crate) producer: Option<String>,
23
+ pub(crate) keywords: Option<Vec<String>>,
24
+ pub(crate) authors: Option<Vec<String>>,
25
+ pub(crate) document_id: Option<String>,
26
+ pub(crate) language: Option<String>,
27
+ pub(crate) creation_date: Option<DateTime>,
28
+ pub(crate) modification_date: Option<DateTime>,
29
+ pub(crate) xmp_extensions: Vec<XmpExtension>,
30
+ pub(crate) text_direction: Option<TextDirection>,
31
+ pub(crate) page_layout: Option<PageLayout>,
32
+ }
33
+
34
+ impl Metadata {
35
+ /// Create new metadata.
36
+ pub fn new() -> Self {
37
+ Self {
38
+ ..Default::default()
39
+ }
40
+ }
41
+
42
+ /// The title of the document.
43
+ pub fn title(mut self, title: String) -> Self {
44
+ if !title.is_empty() {
45
+ self.title = Some(title);
46
+ }
47
+ self
48
+ }
49
+
50
+ /// The description of the document.
51
+ ///
52
+ /// This should be a short, human-readable abstract, summary, or description
53
+ /// of the topic of the document.
54
+ pub fn description(mut self, description: String) -> Self {
55
+ if !description.is_empty() {
56
+ self.description = Some(description);
57
+ }
58
+ self
59
+ }
60
+
61
+ /// The keywords that describe the document.
62
+ pub fn keywords(mut self, keywords: Vec<String>) -> Self {
63
+ if !keywords.is_empty() {
64
+ self.keywords = Some(keywords);
65
+ }
66
+ self
67
+ }
68
+
69
+ /// The main language of the document, as an RFC 3066 language tag.
70
+ ///
71
+ /// This property is required for some export modes, like for example PDF/A-3a.
72
+ pub fn language(mut self, language: String) -> Self {
73
+ self.language = Some(language);
74
+ self
75
+ }
76
+
77
+ /// The creator tool of the document.
78
+ pub fn creator(mut self, creator: String) -> Self {
79
+ if !creator.is_empty() {
80
+ self.creator = Some(creator);
81
+ }
82
+ self
83
+ }
84
+
85
+ /// The producer tool of the document.
86
+ pub fn producer(mut self, producer: String) -> Self {
87
+ if !producer.is_empty() {
88
+ self.producer = Some(producer);
89
+ }
90
+ self
91
+ }
92
+
93
+ /// The authors of the document.
94
+ pub fn authors(mut self, authors: Vec<String>) -> Self {
95
+ if !authors.is_empty() {
96
+ self.authors = Some(authors);
97
+ }
98
+ self
99
+ }
100
+
101
+ /// The creation date of the document.
102
+ pub fn creation_date(mut self, creation_date: DateTime) -> Self {
103
+ self.creation_date = Some(creation_date);
104
+ self
105
+ }
106
+
107
+ /// The last modification date. Defaults to the creation date.
108
+ pub fn modification_date(mut self, modification_date: DateTime) -> Self {
109
+ self.modification_date = Some(modification_date);
110
+ self
111
+ }
112
+
113
+ /// Add text properties with their PDF/A extension schema description.
114
+ /// The caller must supply valid, unique XML names and namespace URIs which
115
+ /// do not collide with built-in metadata. Values are XML-escaped.
116
+ pub fn xmp_extension(mut self, extension: XmpExtension) -> Self {
117
+ self.xmp_extensions.push(extension);
118
+ self
119
+ }
120
+
121
+ /// A document ID.
122
+ ///
123
+ /// This attribute will be used as an identifier for identifying
124
+ /// different versions of the same document.
125
+ pub fn document_id(mut self, document_id: String) -> Self {
126
+ self.document_id = Some(document_id);
127
+ self
128
+ }
129
+
130
+ /// The main text direction of the document.
131
+ pub fn text_direction(mut self, text_direction: TextDirection) -> Self {
132
+ self.text_direction = Some(text_direction);
133
+ self
134
+ }
135
+
136
+ /// How the viewer should lay out the pages.
137
+ pub fn page_layout(mut self, page_layout: PageLayout) -> Self {
138
+ self.page_layout = Some(page_layout);
139
+ self
140
+ }
141
+
142
+ pub(crate) fn has_document_info(&self) -> bool {
143
+ self.title.is_some()
144
+ || self.producer.is_some()
145
+ || self.keywords.is_some()
146
+ || self.authors.is_some()
147
+ || self.creator.is_some()
148
+ || self.creation_date.is_some()
149
+ || self.modification_date.is_some()
150
+ || self.description.is_some()
151
+ }
152
+
153
+ pub(crate) fn serialize_xmp_metadata<'a>(
154
+ &'a self,
155
+ xmp: &mut XmpWriter<'a>,
156
+ sc: &mut SerializeContext,
157
+ instance_id: &str,
158
+ ) {
159
+ if let Some(title) = &self.title {
160
+ xmp.title([(None, title.as_str())]);
161
+ }
162
+
163
+ if let Some(description) = &self.description {
164
+ xmp.description([(None, description.as_str())]);
165
+ }
166
+
167
+ if let Some(keywords) = &self.keywords {
168
+ let joined = keywords.join(", ");
169
+ xmp.pdf_keywords(joined.as_str());
170
+ }
171
+
172
+ match &self.authors {
173
+ Some(authors) if sc.serialize_settings().pdf_version() >= PdfVersion::Pdf20 => {
174
+ // PDF 2.0+ deprecates the document information dictionary, so
175
+ // we can use the array here.
176
+ xmp.creator(authors.iter().map(String::as_str));
177
+ }
178
+ Some(authors) => {
179
+ // Turns out that if the authors are given in both the document
180
+ // information dictionary and the XMP metadata, Acrobat takes a
181
+ // little bit of both: The first author from the document
182
+ // information dictionary and the remaining authors from the XMP
183
+ // metadata.
184
+ //
185
+ // To fix this for Acrobat, we could omit the remaining authors
186
+ // or all metadata from the document information catalog (it is
187
+ // optional) and only write XMP. However, not all other tools
188
+ // (including Apple Preview) read the XMP data. This means we do
189
+ // want to include all authors in the document information
190
+ // dictionary.
191
+ //
192
+ // Thus, the only alternative is to fold all authors into a
193
+ // single `<rdf:li>` in the XMP metadata. This is, in fact,
194
+ // exactly what the PDF/A spec Part 1 section 6.7.3 has to say
195
+ // about the matter. It's a bit weird to not use the array (and
196
+ // it makes Acrobat show the author list in quotes), but there's
197
+ // not much we can do about that.
198
+ let joined = authors.join(", ");
199
+ xmp.creator([joined.as_str()]);
200
+ }
201
+ None => {}
202
+ }
203
+
204
+ if let Some(creator) = &self.creator {
205
+ xmp.creator_tool(creator);
206
+ }
207
+
208
+ if let Some(producer) = &self.producer {
209
+ xmp.producer(producer);
210
+ }
211
+
212
+ if let Some(lang) = &self.language {
213
+ xmp.language([LangId(lang)]);
214
+ }
215
+
216
+ for extension in &self.xmp_extensions {
217
+ for property in &extension.properties {
218
+ xmp.element(&property.name, extension.namespace())
219
+ .value(property.value.as_str());
220
+ }
221
+ }
222
+
223
+ if let Some(date) = self.modification_date.or(self.creation_date).map(xmp_date) {
224
+ xmp.modify_date(date);
225
+ }
226
+ if let Some(date) = self.creation_date.map(xmp_date) {
227
+ xmp.create_date(date);
228
+
229
+ if sc
230
+ .serialize_settings()
231
+ .validators()
232
+ .requires_file_provenance_information()
233
+ {
234
+ let mut history = xmp.history();
235
+ let mut saved = history.add_event();
236
+
237
+ saved
238
+ .action(xmp_writer::ResourceEventAction::Saved)
239
+ .when(date);
240
+
241
+ if !sc
242
+ .serialize_settings()
243
+ .validators()
244
+ .prohibits_instance_id_in_xmp_metadata()
245
+ {
246
+ saved.instance_id(&format!("{instance_id}_source"));
247
+ }
248
+
249
+ saved.finish();
250
+
251
+ let mut converted = history.add_event();
252
+
253
+ converted
254
+ .action(xmp_writer::ResourceEventAction::Converted)
255
+ .when(date);
256
+
257
+ if let Some(creator) = &self.creator {
258
+ converted.software_agent(creator);
259
+ }
260
+
261
+ if !sc
262
+ .serialize_settings()
263
+ .validators()
264
+ .prohibits_instance_id_in_xmp_metadata()
265
+ {
266
+ converted.instance_id(&format!("{instance_id}_source"));
267
+ }
268
+ }
269
+ } else {
270
+ sc.register_validation_error(ValidationError::MissingDocumentDate);
271
+ }
272
+ }
273
+
274
+ pub(crate) fn serialize_document_info(
275
+ &self,
276
+ ref_: &mut Ref,
277
+ pdf: &mut Pdf,
278
+ config: Configuration,
279
+ ) {
280
+ if config.validators().prohibits_info_dict() {
281
+ return;
282
+ }
283
+
284
+ if self.has_document_info() {
285
+ let ref_ = ref_.bump();
286
+ let mut document_info = LazyCell::new(|| pdf.document_info(ref_));
287
+
288
+ // ALl of those are deprecated in PDF 2.0 and will only be written
289
+ // to the XMP metadata.
290
+ if config.version() < PdfVersion::Pdf20 {
291
+ if let Some(title) = &self.title {
292
+ document_info.title(TextStr(title));
293
+ }
294
+
295
+ if let Some(description) = &self.description {
296
+ document_info.subject(TextStr(description));
297
+ }
298
+
299
+ if let Some(keywords) = &self.keywords {
300
+ let joined = keywords.join(", ");
301
+ document_info.keywords(TextStr(&joined));
302
+ }
303
+
304
+ if let Some(authors) = &self.authors {
305
+ let joined = authors.join(", ");
306
+ document_info.author(TextStr(&joined));
307
+ }
308
+
309
+ if let Some(creator) = &self.creator {
310
+ document_info.creator(TextStr(creator));
311
+ }
312
+
313
+ if let Some(producer) = &self.producer {
314
+ document_info.producer(TextStr(producer));
315
+ }
316
+ }
317
+
318
+ if let Some(date_time) = self.modification_date.or(self.creation_date) {
319
+ document_info.modified_date(pdf_date(date_time));
320
+ }
321
+ if let Some(date_time) = self.creation_date {
322
+ document_info.creation_date(pdf_date(date_time));
323
+ }
324
+ }
325
+ }
326
+ }
327
+
328
+ /// A custom XMP schema containing text properties.
329
+ #[derive(Clone, Debug, Hash)]
330
+ pub struct XmpExtension {
331
+ /// Human-readable schema name.
332
+ pub name: String,
333
+ /// Unique XML namespace prefix.
334
+ pub prefix: String,
335
+ /// XML namespace URI.
336
+ pub namespace_uri: String,
337
+ /// Text properties and their schema descriptions.
338
+ pub properties: Vec<XmpProperty>,
339
+ }
340
+
341
+ /// A text property in an XMP extension schema.
342
+ #[derive(Clone, Debug, Hash)]
343
+ pub struct XmpProperty {
344
+ /// XML local name.
345
+ pub name: String,
346
+ /// Property value.
347
+ pub value: String,
348
+ /// Human-readable property description.
349
+ pub description: String,
350
+ /// Whether the property is derived from the document's contents.
351
+ pub internal: bool,
352
+ }
353
+
354
+ impl XmpExtension {
355
+ fn namespace(&self) -> Namespace<'_> {
356
+ Namespace::Custom(Box::new(CustomNamespace::new(
357
+ &self.name,
358
+ &self.prefix,
359
+ &self.namespace_uri,
360
+ )))
361
+ }
362
+
363
+ pub(crate) fn serialize_schema<'a>(&'a self, schemas: &mut PdfAExtSchemasWriter<'_, 'a>) {
364
+ let mut schema = schemas.add_schema();
365
+ schema
366
+ .element("schema", Namespace::PdfASchema)
367
+ .value(self.name.as_str());
368
+ schema
369
+ .element("namespaceURI", Namespace::PdfASchema)
370
+ .value(self.namespace_uri.as_str());
371
+ schema
372
+ .element("prefix", Namespace::PdfASchema)
373
+ .value(self.prefix.as_str());
374
+ let mut properties = schema.properties();
375
+ for property in &self.properties {
376
+ properties
377
+ .add_property()
378
+ .name(&property.name)
379
+ .value_type("Text")
380
+ .category(property.internal)
381
+ .description(&property.description);
382
+ }
383
+ }
384
+ }
385
+
386
+ /// A datetime. Invalid values will be clamped.
387
+ #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
388
+ pub struct DateTime {
389
+ /// The year (0-9999).
390
+ pub(crate) year: u16,
391
+ /// The month (0-11).
392
+ pub(crate) month: Option<u8>,
393
+ /// The day (0-31).
394
+ pub(crate) day: Option<u8>,
395
+ /// The hour (0-23).
396
+ pub(crate) hour: Option<u8>,
397
+ /// The minute (0-59).
398
+ pub(crate) minute: Option<u8>,
399
+ /// The second (0-59).
400
+ pub(crate) second: Option<u8>,
401
+ /// The hour offset from UTC (-23 through 23).
402
+ pub(crate) utc_offset_hour: Option<i8>,
403
+ /// The minute offset from UTC (0-59). Will carry over the sign from
404
+ /// `utc_offset_hour`.
405
+ pub(crate) utc_offset_minute: u8,
406
+ }
407
+
408
+ impl DateTime {
409
+ /// Create a new, minimal date. The year will be clamped within the range
410
+ /// 0-9999.
411
+ #[inline]
412
+ pub fn new(year: u16) -> Self {
413
+ Self {
414
+ year: year.min(9999),
415
+ month: None,
416
+ day: None,
417
+ hour: None,
418
+ minute: None,
419
+ second: None,
420
+ utc_offset_hour: None,
421
+ utc_offset_minute: 0,
422
+ }
423
+ }
424
+
425
+ /// Add the month field. It will be clamped within the range 1-12.
426
+ #[inline]
427
+ pub fn month(mut self, month: u8) -> Self {
428
+ self.month = Some(month.clamp(1, 12));
429
+ self
430
+ }
431
+
432
+ /// Add the day field. It will be clamped within the range 1-31.
433
+ #[inline]
434
+ pub fn day(mut self, day: u8) -> Self {
435
+ self.day = Some(day.clamp(1, 31));
436
+ self
437
+ }
438
+
439
+ /// Add the hour field. It will be clamped within the range 0-23.
440
+ #[inline]
441
+ pub fn hour(mut self, hour: u8) -> Self {
442
+ self.hour = Some(hour.min(23));
443
+ self
444
+ }
445
+
446
+ /// Add the minute field. It will be clamped within the range 0-59.
447
+ #[inline]
448
+ pub fn minute(mut self, minute: u8) -> Self {
449
+ self.minute = Some(minute.min(59));
450
+ self
451
+ }
452
+
453
+ /// Add the second field. It will be clamped within the range 0-59.
454
+ #[inline]
455
+ pub fn second(mut self, second: u8) -> Self {
456
+ self.second = Some(second.min(59));
457
+ self
458
+ }
459
+
460
+ /// Add the offset from UTC in hours. If not specified, the time will be
461
+ /// assumed to be local to the viewer's time zone. It will be clamped within
462
+ /// the range -23-23.
463
+ #[inline]
464
+ pub fn utc_offset_hour(mut self, hour: i8) -> Self {
465
+ self.utc_offset_hour = Some(hour.clamp(-23, 23));
466
+ self
467
+ }
468
+
469
+ /// Add the offset from UTC in minutes. This will have the same sign as set in
470
+ /// [`Self::utc_offset_hour`]. It will be clamped within the range 0-59.
471
+ #[inline]
472
+ pub fn utc_offset_minute(mut self, minute: u8) -> Self {
473
+ self.utc_offset_minute = minute.min(59);
474
+ self
475
+ }
476
+ }
477
+
478
+ /// Converts a datetime to a pdf-writer date.
479
+ pub(crate) fn pdf_date(date_time: DateTime) -> pdf_writer::Date {
480
+ // We always assume a full date with all fields because for some reason
481
+ // Acrobat doesn't like PDF/A-1 files without everything set.
482
+ pdf_writer::Date::new(date_time.year)
483
+ .month(date_time.month.unwrap_or(1))
484
+ .day(date_time.day.unwrap_or(1))
485
+ .hour(date_time.hour.unwrap_or(0))
486
+ .minute(date_time.minute.unwrap_or(0))
487
+ .second(date_time.second.unwrap_or(0))
488
+ .utc_offset_hour(date_time.utc_offset_hour.unwrap_or(0))
489
+ .utc_offset_minute(date_time.utc_offset_minute)
490
+ }
491
+
492
+ /// Converts a datetime to an xmp-writer datetime.
493
+ fn xmp_date(datetime: DateTime) -> xmp_writer::DateTime {
494
+ let timezone = match (datetime.utc_offset_hour, datetime.utc_offset_minute) {
495
+ (Some(h), m) => Some(Timezone::Local {
496
+ hour: h,
497
+ minute: m as i8,
498
+ }),
499
+ _ => Some(Timezone::Utc),
500
+ };
501
+
502
+ // We always assume a full date with all fields because for some reason
503
+ // Acrobat doesn't like PDF/A-1 files without everything set.
504
+ xmp_writer::DateTime {
505
+ year: datetime.year,
506
+ month: Some(datetime.month.unwrap_or(1)),
507
+ day: Some(datetime.day.unwrap_or(1)),
508
+ hour: Some(datetime.hour.unwrap_or(0)),
509
+ minute: Some(datetime.minute.unwrap_or(0)),
510
+ second: Some(datetime.second.unwrap_or(0)),
511
+ timezone,
512
+ }
513
+ }
514
+
515
+ /// The main text direction of the document.
516
+ #[allow(missing_docs)]
517
+ #[derive(Copy, Clone, Debug)]
518
+ pub enum TextDirection {
519
+ LeftToRight,
520
+ RightToLeft,
521
+ }
522
+
523
+ impl TextDirection {
524
+ pub(crate) fn to_pdf(self) -> pdf_writer::types::Direction {
525
+ match self {
526
+ TextDirection::LeftToRight => pdf_writer::types::Direction::L2R,
527
+ TextDirection::RightToLeft => pdf_writer::types::Direction::R2L,
528
+ }
529
+ }
530
+ }
531
+
532
+ /// How the viewer should lay out the pages.
533
+ #[derive(Copy, Clone, Debug)]
534
+ pub enum PageLayout {
535
+ /// Only a single page at a time.
536
+ SinglePage,
537
+ /// A single, continuously scrolling column of pages.
538
+ OneColumn,
539
+ /// Two continuously scrolling columns of pages, laid out with odd-numbered
540
+ /// pages on the left.
541
+ TwoColumnLeft,
542
+ /// Two continuously scrolling columns of pages, laid out with odd-numbered
543
+ /// pages on the right (like in a left-bound book).
544
+ TwoColumnRight,
545
+ /// Only two pages are visible at a time, laid out with odd-numbered pages
546
+ /// on the left. PDF 1.5+.
547
+ TwoPageLeft,
548
+ /// Only two pages are visible at a time, laid out with odd-numbered pages
549
+ /// on the right (like in a left-bound book). PDF 1.5+.
550
+ TwoPageRight,
551
+ }
552
+
553
+ impl PageLayout {
554
+ pub(crate) fn to_pdf(self) -> pdf_writer::types::PageLayout {
555
+ match self {
556
+ PageLayout::SinglePage => pdf_writer::types::PageLayout::SinglePage,
557
+ PageLayout::OneColumn => pdf_writer::types::PageLayout::OneColumn,
558
+ PageLayout::TwoColumnLeft => pdf_writer::types::PageLayout::TwoColumnLeft,
559
+ PageLayout::TwoColumnRight => pdf_writer::types::PageLayout::TwoColumnRight,
560
+ PageLayout::TwoPageLeft => pdf_writer::types::PageLayout::TwoPageLeft,
561
+ PageLayout::TwoPageRight => pdf_writer::types::PageLayout::TwoPageRight,
562
+ }
563
+ }
564
+ }
@@ -0,0 +1,4 @@
1
+ pub mod embed;
2
+ pub mod metadata;
3
+ pub mod outline;
4
+ pub mod tagging;