From 6784a99d927fbdfa045afceb976e1165ba7a85da Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Sat, 12 Apr 2014 20:40:33 -0400 Subject: UTF-8 rune to code page byte translator so that some UTF-8 text can be converted for proper rendering in the PDF document. --- 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 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 +} -- cgit v1.2.1-24-ge1ad