summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
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
+}