Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't support Chinese characters #4

Open
paulrouget opened this issue Jun 25, 2023 · 1 comment
Open

Doesn't support Chinese characters #4

paulrouget opened this issue Jun 25, 2023 · 1 comment

Comments

@paulrouget
Copy link

For example: invoice generate --from "你好"

@pyrite357
Copy link

pyrite357 commented Jul 13, 2023

@paulrouget I got it working by modding the source to use a different font that supports UTF8. You can get the font (NotoSansSC-Regular.ttf) at https://github.com/jsntn/webfonts/ and put it in the same directory as pdf.go

diff --git a/pdf.go b/pdf.go
index 5a1cd55..b10a2e9 100644
--- a/pdf.go
+++ b/pdf.go
@@ -41,7 +41,8 @@ func writeLogo(pdf *gopdf.GoPdf, logo string, from string) {
 }
 
 func writeTitle(pdf *gopdf.GoPdf, title, id, date string) {
-       _ = pdf.SetFont("Inter-Bold", "", 24)
+    pdf.AddTTFFont("NotoSansSC-Regular", "NotoSansSC-Regular.ttf")
+       _ = pdf.SetFont("NotoSansSC-Regular", "", 24)
        pdf.SetTextColor(0, 0, 0)
        _ = pdf.Cell(nil, title)

go build

./invoice generate --title "中文,你好!" && xdg-open invoice.pdf

image

It will be up to @maaslalani to decide what font to use/include/distribute though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants