diff options
author | Kurt <kurt.w.jung@gmail.com> | 2019-05-09 10:21:35 -0400 |
---|---|---|
committer | Kurt <kurt.w.jung@gmail.com> | 2019-05-09 10:21:35 -0400 |
commit | 65c03ae855f64ff46c37f9d58ed572a302bd355d (patch) | |
tree | d8ee86ef5c410ca4d2dda2d96cd49654df28a591 | |
parent | 514e371ce761f71cf004bf0da3246824310b2e4f (diff) |
Handle errors in UTF-8 example
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | fpdf_test.go | 35 | ||||
-rw-r--r-- | go.mod | 6 | ||||
-rw-r--r-- | go.sum | 11 |
4 files changed, 40 insertions, 14 deletions
@@ -9,7 +9,7 @@ check : golint . go vet -all . gofmt -s -l . - goreportcard-cli -v + goreportcard-cli -v | grep -v cyclomatic README.md : doc/document.md pandoc --read=markdown --write=gfm < $< > $@ diff --git a/fpdf_test.go b/fpdf_test.go index 4c1fc05..6b43af0 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -2523,6 +2523,10 @@ func ExampleFpdf_TransformRotate() { // ExampleFpdf_AddUTF8Font demonstrates how use the font // with utf-8 mode func ExampleFpdf_AddUTF8Font() { + var fileStr string + var txtStr []byte + var err error + pdf := gofpdf.New("P", "mm", "A4", "") pdf.AddPage() @@ -2532,22 +2536,27 @@ func ExampleFpdf_AddUTF8Font() { pdf.AddUTF8Font("dejavu", "I", example.FontFile("DejaVuSansCondensed-Oblique.ttf")) pdf.AddUTF8Font("dejavu", "BI", example.FontFile("DejaVuSansCondensed-BoldOblique.ttf")) - txtStr, _ := ioutil.ReadFile(example.TextFile("utf-8test.txt")) + fileStr = example.Filename("Fpdf_AddUTF8Font") + txtStr, err = ioutil.ReadFile(example.TextFile("utf-8test.txt")) + if err == nil { + + pdf.SetFont("dejavu", "B", 17) + pdf.MultiCell(100, 8, "Text in different languages :", "", "C", false) + pdf.SetFont("dejavu", "", 14) + pdf.MultiCell(100, 5, string(txtStr), "", "C", false) + pdf.Ln(15) - pdf.SetFont("dejavu", "B", 17) - pdf.MultiCell(100, 8, "Text in different languages :", "", "C", false) - pdf.SetFont("dejavu", "", 14) - pdf.MultiCell(100, 5, string(txtStr), "", "C", false) - pdf.Ln(15) + txtStr, err = ioutil.ReadFile(example.TextFile("utf-8test2.txt")) + if err == nil { - txtStr, _ = ioutil.ReadFile(example.TextFile("utf-8test2.txt")) - pdf.SetFont("dejavu", "BI", 17) - pdf.MultiCell(100, 8, "Greek text with alignStr = \"J\":", "", "C", false) - pdf.SetFont("dejavu", "I", 14) - pdf.MultiCell(100, 5, string(txtStr), "", "J", false) + pdf.SetFont("dejavu", "BI", 17) + pdf.MultiCell(100, 8, "Greek text with alignStr = \"J\":", "", "C", false) + pdf.SetFont("dejavu", "I", 14) + pdf.MultiCell(100, 5, string(txtStr), "", "J", false) + err = pdf.OutputFileAndClose(fileStr) - fileStr := example.Filename("Fpdf_AddUTF8Font") - err := pdf.OutputFileAndClose(fileStr) + } + } example.Summary(err, fileStr) // Output: // Successfully generated pdf/Fpdf_AddUTF8Font.pdf @@ -1,3 +1,9 @@ module github.com/jung-kurt/gofpdf go 1.12 + +require ( + github.com/boombuler/barcode v1.0.0 + github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58 + golang.org/x/image v0.0.0-20190507092727-e4e5bf290fec +) @@ -0,0 +1,11 @@ +github.com/boombuler/barcode v1.0.0 h1:s1TvRnXwL2xJRaccrdcBQMZxq6X7DvsMogtmJeHDdrc= +github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58 h1:nlG4Wa5+minh3S9LVFtNoY+GVRiudA2e3EVfcCi3RCA= +github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/image v0.0.0-20190507092727-e4e5bf290fec h1:arXJwtMuk5vqI1NHX0UTnNw977rYk5Sl4jQqHj+hun4= +golang.org/x/image v0.0.0-20190507092727-e4e5bf290fec/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |