首页 > 解决方案 > jung-kurt/gofpdf TM 商标符号未正确呈现

问题描述

stringTMSymbol := "™️"
pdf.TransformBegin()
pdf.TransformTranslate(x, y)
pdf.Line(0.0, 0.0, w, 0.0)
pdf.SetXY(0, 0.0)
pdf.SetFont("Arial", "", 14)
pdf.CellFormat(w, 0.33, "URN" + stringTMSymbol, "", 0, "C", false, 0, "")
pdf.Line(0, 0.32, w, 0.32)
pdf.TransformEnd()

代码示例会生成包含无法识别字符的 pdf:

在此处输入图像描述

这应该看起来像:

URN™️

我想这是一个字符编码问题。如何使用 jung-kurt/gofpdf 在 pdf 上渲染 ™️ 符号?

标签: gopdfutf-8

解决方案


解决了

https://godoc.org/github.com/jung-kurt/gofpdf#Fpdf.UnicodeTranslatorFromDescriptor

按照这个例子:

https://github.com/jung-kurt/gofpdf/issues/6

tr := pdf.UnicodeTranslatorFromDescriptor("")
pdf.CellFormat(w, 0.33, "URN" + tr(stringTMSymbol), "", 0, "C", false, 0, "")

推荐阅读