Skip to content

Commit

Permalink
🩹 Do not set default Producer and Creator
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ralfstx committed Jun 29, 2023
1 parent cadc751 commit 5bdc8aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function createDocument(def: DocumentDefinition): Promise<Document>
}

export async function renderDocument(def: DocumentDefinition, doc: Document): Promise<PDFDocument> {
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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5bdc8aa

Please sign in to comment.