Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.74k stars 645 forks source link

getCreationDate has issues parsing some dates #1545

Open saul-prepared opened 10 months ago

saul-prepared commented 10 months ago

What were you trying to do?

Trying to get the creation date of a PDF. The PDF has a creation date of D:20210514143134-5'00'

How did you attempt to do it?

Call the getCreationDate function.

const data = new Uint8Array(doc.Body as Buffer); const pdfDoc = await PDFDocument.load(data, { updateMetadata: false }) let originalCreateDate = moment(pdfDoc.getCreationDate()).utc().toDate();

What actually happened?

It throws the following error "Attempted to convert "D:20210514143134-5'00'" to a date, but it does not match the PDF date string format."

What did you expect to happen?

Expected it to return a date.

How can we reproduce the issue?

Here is the link to the JS fiddle https://jsfiddle.net/3fu4vj2c/1/ The example is the copied and pasted parseDate function. I cannot provide the pdf file that caused the issue because it is a legal document that cannot be shared.

The JS Fiddle has a suggested fix as well.

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

No response