From e982ad5dfea40ff2cfd5d93deb99c82678b8f43e Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Fri, 6 Dec 2013 11:43:41 -0500 Subject: Added SplitLines function by Bruno Michel and demonstration of its use. --- fpdf_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'fpdf_test.go') 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 +} -- cgit v1.2.1-24-ge1ad