From 5bdc8aa40ae0d1ac1d84ac28cecec55199287b88 Mon Sep 17 00:00:00 2001 From: Ralf Sternberg Date: Thu, 29 Jun 2023 12:52:32 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Do=20not=20set=20default=20Produ?= =?UTF-8?q?cer=20and=20Creator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the "Producer" and "Creator" fields in the PDF Info dictionary have been set by pdf-lib. They could be overridden in the document config, but there was no way to remove these fields. Both fields are optional, so there is no need to set them by default. This commit removes the default values. Users can set them as needed in the document definition. --- CHANGELOG.md | 5 +++++ src/document.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5595495..a32111d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ * The attribute `margin` in a document definition now supports a function that returns the margin for a given page. +### Fixed + +* In the PDF metadata, the fields "Creator" and "Producer" are no longer + set to default values. + ## [0.5.0] - 2023-05-18 ### Breaking changes diff --git a/src/document.ts b/src/document.ts index 0936746..0d7cb85 100644 --- a/src/document.ts +++ b/src/document.ts @@ -23,7 +23,7 @@ export async function createDocument(def: DocumentDefinition): Promise } export async function renderDocument(def: DocumentDefinition, doc: Document): Promise { - const pdfDoc = await PDFDocument.create(); + const pdfDoc = await PDFDocument.create({ updateMetadata: false }); pdfDoc.registerFontkit(fontkit); await embedFonts(doc.fonts ?? [], pdfDoc); await embedImages(doc.images ?? [], pdfDoc); @@ -51,6 +51,9 @@ export async function finishDocument(def: DocumentDefinition, pdfDoc: PDFDocumen } function setMetadata(doc: PDFDocument, info?: Metadata) { + const now = new Date(); + doc.setModificationDate(now); + doc.setCreationDate(now); if (info?.title) { doc.setTitle(info.title); }