From 54926dff7aced06e420e30acacf942650e7a6e59 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Thu, 13 Feb 2014 16:10:53 -0500 Subject: Patch provided by Stefan Schroeder to control vertical alignment of text within cell. --- fpdf_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'fpdf_test.go') diff --git a/fpdf_test.go b/fpdf_test.go index e771ac5..aaf5807 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -1086,3 +1086,40 @@ func ExampleFpdf_tutorial20() { // Output: // Successfully generated pdf/tutorial20.pdf } + +// This example demonstrates Stefan Schroeder's code to control vertical +// alignment. +func ExampleFpdf_tutorial21() { + type recType struct { + align, txt string + } + recList := []recType{ + recType{"TL", "top left"}, + recType{"TC", "top center"}, + recType{"TR", "top right"}, + recType{"LM", "middle left"}, + recType{"CM", "middle center"}, + recType{"RM", "middle right"}, + recType{"BL", "bottom left"}, + recType{"BC", "bottom center"}, + recType{"BR", "bottom right"}, + } + pdf := gofpdf.New("P", "mm", "A4", cnFontDir) // A4 210.0 x 297.0 + pdf.SetFont("Helvetica", "", 16) + linkStr := "" + for pageJ := 0; pageJ < 2; pageJ++ { + pdf.AddPage() + pdf.SetMargins(10, 10, 10) + pdf.SetAutoPageBreak(false, 0) + borderStr := "1" + for _, rec := range recList { + pdf.SetXY(20, 20) + pdf.CellFormat(170, 257, rec.txt, borderStr, 0, rec.align, false, 0, linkStr) + borderStr = "" + } + linkStr = "https://code.google.com/p/gofpdf/" + } + pdf.OutputAndClose(docWriter(pdf, 21)) + // Output: + // Successfully generated pdf/tutorial21.pdf +} -- cgit v1.2.1-24-ge1ad