From cae789a4e309eb39bd6145f93361a3745effbb2d Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sat, 10 Oct 2015 06:23:36 -0400 Subject: Add method to fix document creation date --- fpdf.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'fpdf.go') diff --git a/fpdf.go b/fpdf.go index f1c6b58..efe5274 100644 --- a/fpdf.go +++ b/fpdf.go @@ -2986,6 +2986,14 @@ func (f *Fpdf) outf(fmtStr string, args ...interface{}) { f.out(sprintf(fmtStr, args...)) } +// SetCreationDate fixes the document's internal CreationDate value. By +// default, the time when the document is generated is used for this value. +// This method is typically only used for testing purposes. Specify a +// zero-value time to revert to the default behavior +func (f *Fpdf) SetCreationDate(tm time.Time) { + f.creationDate = tm +} + func (f *Fpdf) putpages() { var wPt, hPt float64 var pageSize SizeType @@ -3400,6 +3408,7 @@ func (f *Fpdf) putresources() { } func (f *Fpdf) putinfo() { + var tm time.Time f.outf("/Producer %s", f.textstring("FPDF "+cnFpdfVersion)) if len(f.title) > 0 { f.outf("/Title %s", f.textstring(f.title)) @@ -3416,7 +3425,12 @@ func (f *Fpdf) putinfo() { if len(f.creator) > 0 { f.outf("/Creator %s", f.textstring(f.creator)) } - f.outf("/CreationDate %s", f.textstring("D:"+time.Now().Format("20060102150405"))) + if f.creationDate.IsZero() { + tm = time.Now() + } else { + tm = f.creationDate + } + f.outf("/CreationDate %s", f.textstring("D:"+tm.Format("20060102150405"))) } func (f *Fpdf) putcatalog() { -- cgit v1.2.1-24-ge1ad