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 (
func main() {
pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{ PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
err := pdf.AddTTFFont(“HDZB_5”, “./ttf/zahra.ttf”)
if err != nil {

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


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


It’s really Annoyingly

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.