signintech / gopdf

A simple library for generating PDF written in Go lang
MIT License
2.57k stars 279 forks source link

Displaying proper malayalam text on PDF using Go lang gopdf #126

Open jaytxrx opened 4 years ago

jaytxrx commented 4 years ago

I am trying to generate a PDF document with Malayalam text.

The issue is that the malayalam text is not displayed properly.

Good Text image

Obtained Text from gopdf image

Does anyone know what the issue is ?

The font used is https://smc.org.in/downloads/fonts/meera/Meera-Regular.ttf

Below is the code used

package main
import (
    "log"
    "github.com/signintech/gopdf"
)

func main() {

    pdf := gopdf.GoPdf{}
    pdf.Start(gopdf.Config{ PageSize: *gopdf.PageSizeA4 })  
    pdf.AddPage()
    err := pdf.AddTTFFont("Meera-Regular", "Meera-Regular.ttf")
    if err != nil {
        log.Print(err.Error())
        return
    }

    err = pdf.SetFont("Meera-Regular", "", 14)
    if err != nil {
        log.Print(err.Error())
        return
    }
    pdf.Cell(nil, "അതിവേഗ ഇംഗ്ലീഷ് നിഘണ്ടു ")
    pdf.WritePdf("hello.pdf")

}
jaytxrx commented 4 years ago

Attaching the generated file

hello.pdf

oneplus1000 commented 4 years ago

Maybe it was an issue like https://github.com/signintech/gopdf/issues/50 , you have to change unicode of string before write out because gopdf will print unicode directly.

jaytxrx commented 4 years ago

@oneplus1000 can you make it clear what exactly needs to be changed? I saw the issue that you mentioned but didn't get much clue.