diff options
author | Kurt Jung <kurt.w.jung@code.google.com> | 2014-03-24 07:57:07 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@code.google.com> | 2014-03-24 07:57:07 -0400 |
commit | 1e8f9e3d345377d69d0ca13bd65dfa15503b5a12 (patch) | |
tree | 5e75e9b41e307ff72dd74a06fdab730ea20344a0 | |
parent | c85d881653e1d4fd0df675e0f8aaffa2806de483 (diff) |
Demonstration of escaping characters to match code page layout of currently selected font.
-rw-r--r-- | fpdf_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
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 <a href="http://en.wikipedia.org/wiki/Windows-1252">Wikipedia</a> 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 +} |