summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authord1ngd0 <paul.david.montag@gmail.com>2018-12-12 14:04:24 -0600
committerKurt Jung <kurt.w.jung@gmail.com>2018-12-12 15:04:24 -0500
commita8d8f9e6a80f014f8f5a2388fbf7f409fe9cf263 (patch)
tree5d362727bfa65589c7a6fe0cbf8ed5e5505874fd /fpdf_test.go
parent95702eead4d148c6111f5a3ef7ef7cbc0c906b49 (diff)
Added the ability to have multiple pages in a template (#216)
* Added the ability to have multiple pages in a template Templates are now aware of the number of pages they have. The main additions are the FromPage and FromPages methods which allow you to extract a Template from a template if you pass in the page number. It follows the same page mechanism as FPDF where pages start in the index 1. * Update fpdf_test.go
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index 3e731fd..2fbca9c 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -64,6 +64,42 @@ func TestFpdfImplementPdf(t *testing.T) {
var _ gofpdf.Pdf = (*gofpdf.Tpl)(nil)
}
+// TestPagedTemplate ensures new paged templates work
+func TestPagedTemplate(t *testing.T) {
+ pdf := gofpdf.New("P", "mm", "A4", "")
+ tpl := pdf.CreateTemplate(func(t *gofpdf.Tpl) {
+ // this will be the second page, as a page is already
+ // created by default
+ t.AddPage()
+ t.AddPage()
+ t.AddPage()
+ })
+
+ if tpl.NumPages() != 4 {
+ t.Fatalf("The template does not have the correct number of pages %d", tpl.NumPages())
+ }
+
+ tplPages := tpl.FromPages()
+ for x := 0; x < len(tplPages); x++ {
+ pdf.AddPage()
+ pdf.UseTemplate(tplPages[x])
+ }
+
+ // get the last template
+ tpl2, err := tpl.FromPage(tpl.NumPages())
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // the objects should be the exact same, as the
+ // template will represent the last page by default
+ // therefore no new id should be set, and the object
+ // should be the same object
+ if fmt.Sprintf("%p", tpl2) != fmt.Sprintf("%p", tpl) {
+ t.Fatal("Template no longer respecting initial template object")
+ }
+}
+
// TestIssue0116 addresses issue 116 in which library silently fails after
// calling CellFormat when no font has been set.
func TestIssue0116(t *testing.T) {