summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorMarcus Downing <marcus@bang-on.net>2015-08-04 08:20:25 +0100
committerMarcus Downing <marcus@bang-on.net>2015-08-04 08:20:25 +0100
commit8f46928acb094c8838f75d663b2f560dbf934773 (patch)
tree3553df35e576ac4f05569d31403b715568082100 /fpdf_test.go
parentc00065ecf3d69b0999d803751618ffbeec7a0b56 (diff)
Templating
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go55
1 files changed, 54 insertions, 1 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index 57a2dd4..c21b1ad 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -29,7 +29,7 @@ import (
"strconv"
"strings"
- "github.com/jung-kurt/gofpdf"
+ "github.com/marcusatbang/gofpdf"
)
// Absolute path needed for gocov tool; relative OK for test
@@ -1686,3 +1686,56 @@ func ExampleFpdf_DrawPath() {
// Output:
// Successfully generated pdf/Fpdf_DrawPath_fill.pdf
}
+
+// This example demonstrates creating and using templates
+func ExampleFpdf_CreateTemplate() {
+ pdf := gofpdf.New("P", "mm", "A4", "")
+ pdf.SetCompression(false)
+ // pdf.SetFont("Times", "", 12)
+ template := pdf.CreateTemplate(func(tpl *gofpdf.Tpl) {
+ tpl.Image(imageFile("logo.png"), 6, 6, 30, 0, false, "", 0, "")
+ tpl.SetFont("Arial", "B", 16)
+ tpl.Text(40, 20, "Template says hello")
+ tpl.SetDrawColor(0, 100, 200)
+ tpl.SetLineWidth(2.5)
+ tpl.Line(95, 12, 105, 22)
+ })
+ _, tplSize := template.Size()
+ // fmt.Println("Size:", tplSize)
+ // fmt.Println("Scaled:", tplSize.ScaleBy(1.5))
+
+ template2 := pdf.CreateTemplate(func(tpl *gofpdf.Tpl) {
+ tpl.UseTemplate(template)
+ subtemplate := tpl.CreateTemplate(func(tpl2 *gofpdf.Tpl) {
+ tpl2.Image(imageFile("logo.png"), 6, 86, 30, 0, false, "", 0, "")
+ tpl2.SetFont("Arial", "B", 16)
+ tpl2.Text(40, 100, "Subtemplate says hello")
+ tpl2.SetDrawColor(0, 200, 100)
+ tpl2.SetLineWidth(2.5)
+ tpl2.Line(102, 92, 112, 102)
+ })
+ tpl.UseTemplate(subtemplate)
+ })
+
+ pdf.SetDrawColor(200, 100, 0)
+ pdf.SetLineWidth(2.5)
+ pdf.SetFont("Arial", "B", 16)
+
+ pdf.AddPage()
+ pdf.UseTemplate(template)
+ pdf.UseTemplateScaled(template, gofpdf.PointType{0, 30}, tplSize)
+ pdf.UseTemplateScaled(template, gofpdf.PointType{0, 60}, tplSize.ScaleBy(1.4))
+ pdf.Line(40, 210, 60, 210)
+ pdf.Text(40, 200, "Template example page 1")
+
+ pdf.AddPage()
+ pdf.UseTemplate(template2)
+ pdf.Line(60, 210, 80, 210)
+ pdf.Text(40, 200, "Template example page 2")
+
+ fileStr := exampleFilename("template")
+ err := pdf.OutputFileAndClose(fileStr)
+ summary(err, fileStr)
+ // Output:
+ // Successfully generated pdf/template.pdf
+}