Repository: fschutt/printpdf (language: rust)

Issue:
Add PdfDocumentReference::set_creation_date
To be able to reproducibly generate a PDF document, e. g. for unit tests, it would be good to be able to set the creation date.  If you don’t have any objections, I can try to implement this.


Discussion / hints:
yeah no problem

Fix patch:
diff --git a/src/types/pdf_document.rs b/src/types/pdf_document.rs
index f516afe..18f381c 100644
--- a/src/types/pdf_document.rs
+++ b/src/types/pdf_document.rs
@@ -166,6 +166,17 @@ impl PdfDocumentReference {
         self
     }
 
+    /// Sets the creation date on the document.
+    ///
+    /// Per default, the creation date is set to the current time.
+    #[inline]
+    pub fn with_creation_date(self, creation_date: OffsetDateTime)
+    -> Self
+    {
+        self.document.borrow_mut().metadata.creation_date = creation_date;
+        self
+    }
+
     /// Sets the modification date on the document. Intended to be used when
     /// reading documents that already have a modification date.
     #[inline]


Test patch: