diff options
| author | Kurt Jung <kurt.w.jung@gmail.com> | 2015-10-10 06:23:36 -0400 | 
|---|---|---|
| committer | Kurt Jung <kurt.w.jung@gmail.com> | 2015-10-10 06:23:36 -0400 | 
| commit | cae789a4e309eb39bd6145f93361a3745effbb2d (patch) | |
| tree | fd7a9790cc398b0511d633a3950b5988606f19c3 | |
| parent | b0f3b60a71b8ca327da859e5f4a7cd8eb5bea4e7 (diff) | |
Add method to fix document creation date
| -rw-r--r-- | def.go | 2 | ||||
| -rw-r--r-- | fpdf.go | 16 | 
2 files changed, 17 insertions, 1 deletions
| @@ -19,6 +19,7 @@ package gofpdf  import (  	"bytes"  	"io" +	"time"  )  // Version of FPDF from which this package is derived @@ -216,6 +217,7 @@ type Fpdf struct {  	author           string                    // author  	keywords         string                    // keywords  	creator          string                    // creator +	creationDate     time.Time                 // override for dcoument CreationDate value  	aliasNbPagesStr  string                    // alias for total number of pages  	pdfVersion       string                    // PDF version number  	fontDirStr       string                    // location of font definition files @@ -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() { | 
