summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@code.google.com>2013-12-06 11:43:41 -0500
committerKurt Jung <kurt.w.jung@code.google.com>2013-12-06 11:43:41 -0500
commite982ad5dfea40ff2cfd5d93deb99c82678b8f43e (patch)
tree37b7c5fe6d875734e0fee70596faff814535a04a /fpdf_test.go
parent41616d85f464af97732fb32ba891847003c8c082 (diff)
Added SplitLines function by Bruno Michel and demonstration of its use.
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index 5edc6c8..d70875a 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -1131,3 +1131,30 @@ func ExampleFpdf_tutorial18() {
// Output:
// Successfully generated pdf/tutorial18.pdf
}
+
+// Example to demonstrate Bruno Michel's line splitting function.
+func ExampleFpdf_tutorial19() {
+ const (
+ fontPtSize = 18.0
+ lineHt = fontPtSize * 25.4 / 72.0
+ wd = 100.0
+ )
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir) // A4 210.0 x 297.0
+ pdf.SetFont("Times", "", fontPtSize)
+ pdf.AddPage()
+ pdf.SetMargins(10, 10, 10)
+ lines := pdf.SplitLines([]byte(lorem()), wd)
+ ht := float64(len(lines)) * lineHt
+ y := (297.0 - ht) / 2.0
+ pdf.SetDrawColor(128, 128, 128)
+ pdf.SetFillColor(255, 255, 210)
+ x := (210.0 - (wd + 40.0)) / 2.0
+ pdf.Rect(x, y-20.0, wd+40.0, ht+40.0, "FD")
+ pdf.SetY(y)
+ for _, line := range lines {
+ pdf.CellFormat(190.0, lineHt, string(line), "", 1, "C", false, 0, "")
+ }
+ pdf.OutputAndClose(docWriter(pdf, 19))
+ // Output:
+ // Successfully generated pdf/tutorial19.pdf
+}