maaslalani / invoice

Command line invoice generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't support Chinese characters

paulrouget opened this issue · comments

commented

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

@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.