summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt Jung <kurt.w.jung@code.google.com>2014-04-12 20:40:33 -0400
committerKurt Jung <kurt.w.jung@code.google.com>2014-04-12 20:40:33 -0400
commit6784a99d927fbdfa045afceb976e1165ba7a85da (patch)
treee302a7ac8f1f332386eb3f60092882d7f672ae02 /fpdf_test.go
parent202a1a1b9f07994138de669f4d8b42b4c0bddcc2 (diff)
UTF-8 rune to code page byte translator so that some UTF-8 text can be converted for proper rendering in the PDF document.
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 303fdc7..7c96411 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -1158,3 +1158,30 @@ func ExampleFpdf_tutorial22() {
// Output:
// Successfully generated pdf/tutorial22.pdf
}
+
+// This example demonstrates the conversion of UTF-8 strings to an 8-bit font
+// encoding.
+func ExampleFpdf_tutorial23() {
+ pdf := gofpdf.New("P", "mm", "A4", cnFontDir) // A4 210.0 x 297.0
+ fontSize := 16.0
+ pdf.SetFont("Helvetica", "", fontSize)
+ ht := pdf.PointConvert(fontSize)
+ tr := pdf.UnicodeTranslatorFromDescriptor("") // Default: "cp1252"
+ write := func(str string) {
+ // fmt.Println(str, tr(str))
+ pdf.CellFormat(190, ht, tr(str), "", 1, "C", false, 0, "")
+ pdf.Ln(ht)
+ }
+ pdf.AddPage()
+ str := ` gofpdf provides a translator that will convert any UTF-8 code point ` +
+ `that is present in the specified code page.`
+ pdf.MultiCell(190, ht, str, "", "L", false)
+ pdf.Ln(2 * ht)
+ write("Voix ambiguë d'un cœur qui au zéphyr préfère les jattes de kiwi.")
+ write("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.")
+ write("Heizölrückstoßabdämpfung")
+ write("Forårsjævndøgn / Efterårsjævndøgn")
+ pdf.OutputAndClose(docWriter(pdf, 23))
+ // Output:
+ // Successfully generated pdf/tutorial23.pdf
+}