foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.91k stars 1.15k forks source link

Off by one error in pdfkit meta data month conversion? #447

Closed pogilvie closed 8 years ago

pogilvie commented 8 years ago

Just finished my first pdfkit project and the results are beautiful! Thank You!

I noticed that the reported CreationDate: was wrong. I think that this is due to the fact that the javascript library function somedate.getMonth() reports month numbers as 0 based. (January is returned as month 0 not 1.) PDF dates expect January as '01'.

With the patch below the linux pdfinfo utility now reports 'Nov' (it was reporting 'Oct' before.)

Creator: PDFKit Producer: PDFKit CreationDate: Thu Nov 19 22:25:49 2015

@@ -64,7 +64,7 @@ class PDFObject

     else if object instanceof Date
       '(D:' + pad(object.getUTCFullYear(), 4) +
-              pad(object.getUTCMonth(), 2) + 
+             pad(object.getUTCMonth() + 1, 2) + 
               pad(object.getUTCDate(), 2) + 
               pad(object.getUTCHours(), 2) + 
               pad(object.getUTCMinutes(), 2) + 
vbuser2004 commented 8 years ago

+1

devongovett commented 8 years ago

Fixed in #449.