I can not use Arabic language in pdf

hi all

I am new to learning Golang

I want to use the library gopdf https://github.com/signintech/gopdf
But it does not support the Arabic
I want solve the problem

package main

import (
“log”
github.com/signintech/gopdf
)
func main() {
pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{ PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
pdf.AddPage()
err := pdf.AddTTFFont(“HDZB_5”, “./ttf/zahra.ttf”)
if err != nil {
log.Print(err.Error())
return
}

err = pdf.SetFont("HDZB_5", "", 14)
if err != nil {
	log.Print(err.Error())
	return
}
pdf.Cell(nil, "هُنَالِكَ دَعَا زَكَرِيَّا رَبَّهُ قَالَ رَبِّ هَبْ لِي مِنْ لَدُنْكَ ذُرِّيَّةً طَيِّبَةً إِنَّكَ سَمِيعُ الدُّعَاءِ")
pdf.WritePdf("test1.pdf")

}

Annoyingly, gopodf doesn’t support unicode by default as you might expect. The default code page for text seems to be cp1252 (!). You can use UnicodeTranslatorFromDescriptor to wrap your text and translate to this code page if using european text, but I’m not sure if that will work for arabic unfortunately. Maybe someone else who knows the library better than me will be able to help.

1 Like

@kennygrant

It’s really Annoyingly
:weary:

I am using different library for create pdf documents. And I must created font definition files in JSON at first. Read more there: https://github.com/jung-kurt/gofpdf#conversion-notes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.