summaryrefslogtreecommitdiff
path: root/fpdf.go
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@gmail.com>2015-10-10 14:16:23 -0400
committerKurt Jung <kurt.w.jung@gmail.com>2015-10-10 14:16:23 -0400
commit5847afd8a205853a7effbf749b7a388ae325eb24 (patch)
tree4842ab4870a4786a3d6d8218e24e71f1978e00dd /fpdf.go
parente924055b983321336e31f556f5235ea79fe72134 (diff)
Introduce helper functions to set default catalog sort flag and creation date value. Remove regular expression scheme that effectively ignored the embedded creation date when comparing PDFs.
Diffstat (limited to 'fpdf.go')
-rw-r--r--fpdf.go42
1 files changed, 38 insertions, 4 deletions
diff --git a/fpdf.go b/fpdf.go
index d501574..aeb0c3e 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -42,6 +42,11 @@ import (
"time"
)
+var gl struct {
+ catalogSort bool
+ creationDate time.Time
+}
+
type fmtBuffer struct {
bytes.Buffer
}
@@ -180,6 +185,8 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType)
// Set default PDF version number
f.pdfVersion = "1.3"
f.layerInit()
+ f.catalogSort = gl.catalogSort
+ f.creationDate = gl.creationDate
return
}
@@ -2987,6 +2994,13 @@ func (f *Fpdf) outf(fmtStr string, args ...interface{}) {
f.out(sprintf(fmtStr, args...))
}
+// SetDefaultCatalogSort sets the default value of the catalog sort flag that
+// will be used when initializing a new Fpdf instance. See SetCatalogSort() for
+// more details.
+func SetDefaultCatalogSort(flag bool) {
+ gl.catalogSort = flag
+}
+
// SetCatalogSort sets a flag that will be used, if true, to consistently order
// the document's internal resource catalogs. This method is typically only
// used for test purposes.
@@ -2994,10 +3008,17 @@ func (f *Fpdf) SetCatalogSort(flag bool) {
f.catalogSort = flag
}
+// SetDefaultCreationDate sets the default value of the document creation date
+// that will be used when initializing a new Fpdf instance. See
+// SetCreationDate() for more details.
+func SetDefaultCreationDate(tm time.Time) {
+ gl.creationDate = tm
+}
+
// 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
+// zero-value time to revert to the default behavior.
func (f *Fpdf) SetCreationDate(tm time.Time) {
f.creationDate = tm
}
@@ -3346,9 +3367,22 @@ func (f *Fpdf) putxobjectdict() {
func (f *Fpdf) putresourcedict() {
f.out("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]")
f.out("/Font <<")
- for _, font := range f.fonts {
- // foreach($this->fonts as $font)
- f.outf("/F%d %d 0 R", font.I, font.N)
+ {
+ var keyList []string
+ var font fontDefType
+ var key string
+ for key = range f.fonts {
+ keyList = append(keyList, key)
+ }
+ if f.catalogSort {
+ sort.Strings(keyList)
+ }
+ for _, key = range keyList {
+ font = f.fonts[key]
+ // for _, font := range f.fonts {
+ // foreach($this->fonts as $font)
+ f.outf("/F%d %d 0 R", font.I, font.N)
+ }
}
f.out(">>")
f.out("/XObject <<")