From bb287515d3b5c5b4ca7665a64a9224e8b6038804 Mon Sep 17 00:00:00 2001 From: Paul Montag Date: Wed, 31 Oct 2018 19:56:01 -0500 Subject: Added Ability to turn template into a byte string --- fpdf_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 4774ec6..e212d95 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -19,6 +19,7 @@ package gofpdf_test import ( "bufio" "bytes" + "encoding/gob" "fmt" "io" "io/ioutil" @@ -1950,10 +1951,23 @@ func ExampleFpdf_CreateTemplate() { pdf.SetLineWidth(2.5) pdf.SetFont("Arial", "B", 16) + template3 := new(gofpdf.FpdfTpl) + b := new(bytes.Buffer) + enc := gob.NewEncoder(b) + + if err := enc.Encode(template); err != nil { + pdf.SetError(err) + } + + dec := gob.NewDecoder(b) + if err := dec.Decode(template3); err != nil { + pdf.SetError(err) + } + pdf.AddPage() - pdf.UseTemplate(template) - pdf.UseTemplateScaled(template, gofpdf.PointType{X: 0, Y: 30}, tplSize) - pdf.UseTemplateScaled(template, gofpdf.PointType{X: 0, Y: 60}, tplSize.ScaleBy(1.4)) + pdf.UseTemplate(template3) + pdf.UseTemplateScaled(template3, gofpdf.PointType{X: 0, Y: 30}, tplSize) + pdf.UseTemplateScaled(template3, gofpdf.PointType{X: 0, Y: 60}, tplSize.ScaleBy(1.4)) pdf.Line(40, 210, 60, 210) pdf.Text(40, 200, "Template example page 1") -- cgit v1.2.1-24-ge1ad From 01381ea7603b12304064fcd01a49b1cc4434b4ca Mon Sep 17 00:00:00 2001 From: Paul Montag Date: Wed, 7 Nov 2018 08:51:37 -0600 Subject: Created helper functions for serialiation --- fpdf_test.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index e212d95..19bc533 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -19,7 +19,6 @@ package gofpdf_test import ( "bufio" "bytes" - "encoding/gob" "fmt" "io" "io/ioutil" @@ -1951,18 +1950,9 @@ func ExampleFpdf_CreateTemplate() { pdf.SetLineWidth(2.5) pdf.SetFont("Arial", "B", 16) - template3 := new(gofpdf.FpdfTpl) - b := new(bytes.Buffer) - enc := gob.NewEncoder(b) - - if err := enc.Encode(template); err != nil { - pdf.SetError(err) - } - - dec := gob.NewDecoder(b) - if err := dec.Decode(template3); err != nil { - pdf.SetError(err) - } + // serialize and deserialize template + b, _ := template2.Serialize() + template3, _ := gofpdf.DeserializeTemplate(b) pdf.AddPage() pdf.UseTemplate(template3) -- cgit v1.2.1-24-ge1ad From 193187d077554b92944a4757e202d1300e1ed1fb Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 10 Nov 2018 12:06:51 -0500 Subject: Added some comments to new encoding/decoding methods --- fpdf_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index 19bc533..68a26ad 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -1957,12 +1957,12 @@ func ExampleFpdf_CreateTemplate() { pdf.AddPage() pdf.UseTemplate(template3) pdf.UseTemplateScaled(template3, gofpdf.PointType{X: 0, Y: 30}, tplSize) - pdf.UseTemplateScaled(template3, gofpdf.PointType{X: 0, Y: 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.UseTemplateScaled(template3, gofpdf.PointType{X: 0, Y: 30}, tplSize.ScaleBy(1.4)) pdf.Line(60, 210, 80, 210) pdf.Text(40, 200, "Template example page 2") -- cgit v1.2.1-24-ge1ad