From 19ac748275dda1bd9cb6a618c380a18482a2da71 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 20 Jul 2019 10:10:49 -0400 Subject: Use file as reader for ImageOptionsReader --- fpdf_test.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fpdf_test.go b/fpdf_test.go index 5ef88aa..54de6c2 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -861,22 +861,29 @@ func ExampleFpdf_ImageOptions() { // ImageOption struct can be used to affect horizontal image placement. func ExampleFpdf_ImageOptionsReader() { var opt gofpdf.ImageOptions + var pdfStr, imgStr string + var fl *os.File + var err error + pdfStr = example.Filename("Fpdf_ImageOptionsReader") pdf := gofpdf.New("P", "mm", "A4", "") pdf.AddPage() pdf.SetFont("Arial", "", 11) pdf.SetX(60) opt.ImageType = "png" - bytes, err := ioutil.ReadAll(example.ImageFile("logo.png")) - if err!=nil{ - t.Fatal(err) + imgStr = example.ImageFile("logo.png") + fl, err = os.Open(imgStr) + if err == nil { + pdf.ImageOptionsReader(imgStr, fl, -10, 10, 30, 0, false, opt, 0, "") + opt.AllowNegativePosition = true + _, err = fl.Seek(0, 0) + if err == nil { + pdf.ImageOptionsReader(imgStr, fl, -10, 50, 30, 0, false, opt, 0, "") + err = pdf.OutputFileAndClose(pdfStr) + } + fl.Close() } - pdf.ImageOptionsReader(example.ImageFile("logo.png"), bytes.NewReader(bytes),-10, 10, 30, 0, false, opt, 0, "") - opt.AllowNegativePosition = true - pdf.ImageOptionsReader(example.ImageFile("logo.png"),bytes.NewReader(bytes), -10, 50, 30, 0, false, opt, 0, "") - fileStr := example.Filename("Fpdf_ImageOptionsReader") - err := pdf.OutputFileAndClose(fileStr) - example.Summary(err, fileStr) + example.Summary(err, pdfStr) // Output: // Successfully generated pdf/Fpdf_ImageOptionsReader.pdf } -- cgit v1.2.1-24-ge1ad