From 1e8f9e3d345377d69d0ca13bd65dfa15503b5a12 Mon Sep 17 00:00:00 2001 From: Kurt Jung Date: Mon, 24 Mar 2014 07:57:07 -0400 Subject: Demonstration of escaping characters to match code page layout of currently selected font. --- fpdf_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fpdf_test.go b/fpdf_test.go index be55031..303fdc7 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -1129,3 +1129,32 @@ func ExampleFpdf_tutorial21() { // Output: // Successfully generated pdf/tutorial21.pdf } + +// This example demonstrates the use of characters in the high range of the +// Windows-1252 code page (gofdpf default). +func ExampleFpdf_tutorial22() { + pdf := gofpdf.New("P", "mm", "A4", cnFontDir) // A4 210.0 x 297.0 + fontSize := 16.0 + pdf.SetFont("Helvetica", "", fontSize) + ht := pdf.PointConvert(fontSize) + write := func(str string) { + pdf.CellFormat(190, ht, str, "", 1, "C", false, 0, "") + pdf.Ln(ht) + } + pdf.AddPage() + htmlStr := `Until gofpdf supports UTF-8 encoded source text, source text needs ` + + `to be specified with all special characters escaped to match the code page ` + + `layout of the currently selected font. By default, gofdpf uses code page 1252.` + + ` See Wikipedia for ` + + `a table of this layout.` + html := pdf.HTMLBasicNew() + html.Write(ht, htmlStr) + pdf.Ln(2 * ht) + write("Voix ambigu\xeb d'un c\x9cur qui au z\xe9phyr pr\xe9f\xe8re les jattes de kiwi.") + write("Falsches \xdcben von Xylophonmusik qu\xe4lt jeden gr\xf6\xdferen Zwerg.") + write("Heiz\xf6lr\xfccksto\xdfabd\xe4mpfung") + write("For\xe5rsj\xe6vnd\xf8gn / Efter\xe5rsj\xe6vnd\xf8gn") + pdf.OutputAndClose(docWriter(pdf, 22)) + // Output: + // Successfully generated pdf/tutorial22.pdf +} -- cgit v1.2.1-24-ge1ad