unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.47k stars 250 forks source link

[BUG] Some romanian diacritics are not rendered in the generated PDF #484

Closed andob closed 2 years ago

andob commented 2 years ago

Description

When trying to generate a PDF containing text with romanian diacritics, some diacritics will not get displayed in the generated PDF file.

Steps to reproduce

func main() {
    err := license.SetLicenseKey(..........)
    if err != nil {
        panic(err)
    }

    font, err := model.NewStandard14Font("Times-Roman")
    if err != nil {
        panic(err)
    }

    pdf := creator.New()
    pdf.SetPageSize(creator.PageSizeA4)
    pdf.SetPageMargins(30, 30, 30, 30)

    paragraph := pdf.NewParagraph("ĂÂÎŞŢăâîşţ")
    paragraph.SetFont(font)
    paragraph.SetFontSize(50)
    paragraph.SetTextAlignment(creator.TextAlignmentCenter)

    err = pdf.Draw(paragraph)
    if err != nil {
        panic(err)
    }

    err = pdf.WriteToFile("diacritics.pdf")
    if err != nil {
        panic(err)
    }

    fmt.Println("PDF was generated!")
}

Expected Behavior

A PDF file containing ĂÂÎŞŢăâîşţ

Actual Behavior

A PDF file containing only ÂÎâî

Attachments

diacritics.pdf

github-actions[bot] commented 2 years ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

sampila commented 2 years ago

Hi @andob, been checking on this issue, the glyphs are missing because the font didn't support those glyphs. Here's a code snippet and font that I use to get the result without missing glyphs.

package main

import (
    "fmt"
    "os"

    "github.com/unidoc/unipdf/v3/common/license"
    "github.com/unidoc/unipdf/v3/creator"
    "github.com/unidoc/unipdf/v3/model"
)

func main() {
    err := license.SetMeteredKey(os.Getenv("UNIDOC_LICENSE_API_KEY"))
    if err != nil {
        panic(err)
    }

    font, err := model.NewCompositePdfFontFromTTFFile("times.ttf")
    if err != nil {
        panic(err)
    }

    pdf := creator.New()
    pdf.SetPageSize(creator.PageSizeA4)
    pdf.SetPageMargins(30, 30, 30, 30)

    paragraph := pdf.NewParagraph("ĂÂÎŞŢăâîşţ")
    paragraph.SetFont(font)
    paragraph.SetFontSize(50)
    paragraph.SetTextAlignment(creator.TextAlignmentCenter)

    err = pdf.Draw(paragraph)
    if err != nil {
        panic(err)
    }

    err = pdf.WriteToFile("diacritics.pdf")
    if err != nil {
        panic(err)
    }

    fmt.Println("PDF was generated!")
}

Font: arial.zip Result: diacritics.pdf

andob commented 2 years ago

thanks!