summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2019-07-20 10:10:49 -0400
committerKurt <kurt.w.jung@gmail.com>2019-07-20 10:10:49 -0400
commit19ac748275dda1bd9cb6a618c380a18482a2da71 (patch)
tree94a310925be987d75efd4fdaa7292572ac8cfef8
parentacaf282a0e3bde4d968e13541d61a0c8f8db42ac (diff)
Use file as reader for ImageOptionsReader
-rw-r--r--fpdf_test.go25
1 files 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
}