diff options
author | Kurt Jung <kurt.w.jung@gmail.com> | 2015-08-12 16:12:43 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@gmail.com> | 2015-08-12 16:12:43 -0400 |
commit | 0ab52d3f38a38a63fe1bba1a757fe4f28cd6a026 (patch) | |
tree | b3e1222cdc4f7aca41b3ac39b4e2168ac77ee36e /fpdf_test.go | |
parent | 798fdbd15806d1b27a36d47f394cb58b06a9af1e (diff) | |
parent | 3c7e84a50bb3a1b617b6820d23ba2edcadf4fd6c (diff) |
Merge branch 'templating' of https://github.com/marcusatbang/gofpdf into marcusatbang-templating
Diffstat (limited to 'fpdf_test.go')
-rw-r--r-- | fpdf_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go index 57a2dd4..e4b8df4 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -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("Fpdf_CreateTemplate") + err := pdf.OutputFileAndClose(fileStr) + summary(err, fileStr) + // Output: + // Successfully generated pdf/Fpdf_CreateTemplate.pdf +} |