summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@code.google.com>2013-11-07 20:49:59 -0500
committerKurt Jung <kurt.w.jung@code.google.com>2013-11-07 20:49:59 -0500
commitc99f8c8fbf0124fcd2f509132edad09349aa3710 (patch)
treee44e5f17d2d48a68259c7b81253e6f4a4f4cfce9 /fpdf_test.go
parent4188061a94636ec37b26813d79824789f0deb7d5 (diff)
Lawrence Kesteloot provided code to allow an image's extent to be determined prior to placement.
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index ccdf1bf..b683b9c 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -22,6 +22,7 @@ import (
"fmt"
"io/ioutil"
"os"
+ "path/filepath"
"regexp"
"strings"
)
@@ -1083,3 +1084,52 @@ func ExampleFpdf_tutorial17() {
// Output:
// Successfully generated pdf/tutorial17.pdf
}
+
+// Example to demonstrate Lawrence Kesteloot's image registration code.
+func ExampleFpdf_tutorial18() {
+ const (
+ margin = 10
+ wd = 210
+ ht = 297
+ )
+ fileList := []string{
+ "logo-gray.png",
+ "logo.jpg",
+ "logo.png",
+ "logo-rgb.png",
+ "logo-progressive.jpg",
+ }
+ var infoPtr *gofpdf.ImageInfoType
+ var fileStr string
+ var imgWd, imgHt, lf, tp float64
+ pdf := gofpdf.New("P", "mm", "A4", FONT_DIR)
+ pdf.AddPage()
+ pdf.SetMargins(10, 10, 10)
+ pdf.SetFont("Helvetica", "", 15)
+ for j, str := range fileList {
+ fileStr = filepath.Join(IMG_DIR, str)
+ infoPtr = pdf.RegisterImage(fileStr, "")
+ imgWd, imgHt = infoPtr.Extent()
+ switch j {
+ case 0:
+ lf = margin
+ tp = margin
+ case 1:
+ lf = wd - margin - imgWd
+ tp = margin
+ case 2:
+ lf = (wd - imgWd) / 2.0
+ tp = (ht - imgHt) / 2.0
+ case 3:
+ lf = margin
+ tp = ht - imgHt - margin
+ case 4:
+ lf = wd - imgWd - margin
+ tp = ht - imgHt - margin
+ }
+ pdf.Image(fileStr, lf, tp, imgWd, imgHt, false, "", 0, "")
+ }
+ pdf.OutputAndClose(docWriter(pdf, 18))
+ // Output:
+ // Successfully generated pdf/tutorial18.pdf
+}