jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.29k stars 772 forks source link

Charset issue with UTF-8 characters #326

Closed Fank closed 4 years ago

Fank commented 4 years ago

I tried following

    // Logo
    pdf.SetFont("Arial", "B", 21)
    pdf.SetXY(2, 2)
    pdf.Cell(40, 10, "KUEGNE+NAGEL")

    // Consignee
    pdf.SetXY(2, 10)
    pdf.SetFont("Arial", "", 8)
    pdf.Cell(10, 10, "Consignee")

    pdf.SetXY(2, 14)
    pdf.SetFont("Arial", "", 10)
    pdf.Cell(10, 10, "Testemfänger")

    pdf.SetXY(2, 18)
    pdf.SetFont("Arial", "", 10)
    pdf.Cell(10, 10, "Testempfänger Straße 1")

    pdf.SetXY(2, 24)
    pdf.SetFont("Arial", "B", 18)
    pdf.Cell(10, 10, "DE 94315")

    pdf.SetXY(2, 30)
    pdf.SetFont("Arial", "", 10)
    pdf.Cell(10, 10, "Straubing")

And this is the result image

jung-kurt commented 4 years ago

You will need to either fuss with code pages (see this example) or load a UTF-8 TrueType font (see this example).

Fank commented 4 years ago

Ok, but why doesn't it support utf-8 by default?

This is the first golang library where i had encoding issues by default.

jung-kurt commented 4 years ago

Ok, but why doesn't it support utf-8 by default?

This package was ported from FPDF which itself does not support UTF-8. UTF-8 support in gofpdf was added earlier this year. Additional work will be needed to apply this support to the reader-embedded fonts. Use gopdf if you don't want to bother with code pages.

Fank commented 4 years ago

Thanks for the info and help, problem solved.