summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorJelmer Snoeck <jelmer.snoeck@gmail.com>2015-09-25 13:46:33 +0100
committerJelmer Snoeck <jelmer.snoeck@gmail.com>2015-09-25 13:52:55 +0100
commit04e0bd700c8e33c22e277c2c4898eaf9962f461f (patch)
tree32b65db95f3537d2926f11004c4966e21c2aba00 /fpdf_test.go
parent02db05c2cda70eb7ae66c31af83b355917b9694b (diff)
Fpdf: add WriteAligned.
WriteAligned allows a user to write a single string and align it. Previously, Write() would only write with Left alignment. Sometimes, you want to align a specific text string to the center or the right. HTMLBasic: add <center> tag. This allows a user to center text within the HTML block. This way they do not have to split up their input. A new line will be created automatically before and after the centered text.
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index ff8c5da..966767f 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -463,6 +463,7 @@ func ExampleFpdf_HTMLBasicNew() {
_, lineHt = pdf.GetFontSize()
htmlStr := `You can now easily print text mixing different styles: <b>bold</b>, ` +
`<i>italic</i>, <u>underlined</u>, or <b><i><u>all at once</u></i></b>!<br><br>` +
+ `<center>You can also center text.</center>` +
`You can also insert links on text, such as ` +
`<a href="http://www.fpdf.org">www.fpdf.org</a>, or on an image: click on the logo.`
html := pdf.HTMLBasicNew()
@@ -488,6 +489,25 @@ func ExampleFpdf_AddFont() {
// Successfully generated pdf/Fpdf_AddFont.pdf
}
+// This example demonstrates how to align text with the Write function.
+func ExampleFpdf_WriteAligned() {
+ pdf := gofpdf.New("P", "mm", "A4", example.FontDir())
+ pdf.AddPage()
+ pdf.SetFont("Helvetica", "", 12)
+ pdf.WriteAligned(0, 35, "This text is the default alignment, Left", "")
+ pdf.Ln(35)
+ pdf.WriteAligned(0, 35, "This text is aligned Left", "L")
+ pdf.Ln(35)
+ pdf.WriteAligned(0, 35, "This text is aligned Center", "C")
+ pdf.Ln(35)
+ pdf.WriteAligned(0, 35, "This text is aligned Right", "R")
+ fileStr := example.Filename("Fpdf_WriteAligned")
+ err := pdf.OutputFileAndClose(fileStr)
+ example.Summary(err, fileStr)
+ // Output:
+ // Successfully generated pdf/Fpdf_WriteAligned.pdf
+}
+
// This example demonstrates how images are included in documents.
func ExampleFpdf_Image() {
pdf := gofpdf.New("P", "mm", "A4", "")