QuestPDF / QuestPDF

QuestPDF is a modern open-source .NET library for PDF document generation. Offering comprehensive layout engine powered by concise and discoverable C# Fluent API. Easily generate PDF reports, invoices, exports, etc.

Home Page:https://www.questpdf.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Devanagari font rendering Issue Linux

iAmBipinPaul opened this issue · comments

I have code like this.

 QuestPDF.Settings.CheckIfAllTextGlyphsAreAvailable = false;
        QuestPDF.Settings.License = LicenseType.Community;
 [HttpGet("CreatePDF")]
    public  IActionResult CreatePDF()
    {
       
      var res=  Document.Create(container =>
        {
            container
                .Page(page =>
                {
                    page.Size(PageSizes.A4); ;
                    page.Content()
                        .Column(x =>
                        {
                            x.Item().Text("Mixed line: This 中文");
                            x.Item().Text("감사합니다 korean");
                            x.Item().Text("谢谢 chinese");
                            x.Item().Text("ありがとう ございます japanese");
                            x.Item().Text("நன்றி tamil");
                            x.Item().Text("धन्यवाद Hindi");
                            x.Item().Text("ขอบคุณ Thai");
                            x.Item().Text("teşekkürler Turkish");
                            x.Item().Text("ಧನ್ಯವಾದಗಳು Kannada");
                        });
                });
        }).GeneratePdf();
        return File(res, "application/pdf");
    }

it works on Windows but not on Linux, I've installed all the necessary fronts as need (details on sample project).

as per the documentation going forward with version 2024.3.0, we do not need to add fallback method it should work automatically.

here I have sample project.
https://github.com/iAmBipinPaul/QuestPDF.Devanagari.Issue

image

Its exactly font problem, also you dont have to install them, you can specify font file path as blow


        if (!string.IsNullOrEmpty(_options.FontPath))
        {
            FontManager.RegisterFont(File.OpenRead(_options.FontPath));
        }

        if (!string.IsNullOrEmpty(_options.FallBackFontPath))
        {
            FontManager.RegisterFont(File.OpenRead(_options.FallBackFontPath));
        }
Document.Create(pdf =>
        {
            pdf.Page(pageHandler =>
            {
                pageHandler.If(
                    !string.IsNullOrEmpty(_options.FontName),
                    x => x.DefaultTextStyle(text => 
                        text.FontFamily(_options.FontName)
                        .Fallback(text => text.FontFamily(_options.FallBackFontName)).DirectionAuto()));

I have a similar issue with fonts on linux:

An unhandled exception has occurred while executing the request.
      QuestPDF.Drawing.Exceptions.DocumentDrawingException: Could not find an appropriate font fallback for the following glyphs: 
      $U-0069 'i'
      U-0044 'D'
      U-0041 'A'
      U-0068 'h'
      U-0047 'G'
      U-0020 ' '
      U-0052 'R'
      U-0048 'H'
      U-0065 'e'
      U-0072 'r'
      U-0063 'c'
      U-0074 't'
      U-0073 's'
      U-0076 'v' 
      
      Possible solutions: 
      1) Install fonts that contain missing glyphs in your runtime environment. 
      2) Configure the fallback TextStyle using the 'TextStyle.FontFamilyFallback' method. 
      3) Register additional application specific fonts using the 'FontManager.RegisterFont' method. 
      ```
      
      on windows everything works fine, but on linux that exception is thrown.
      My Pdf just contains some svgs and some basic words

Its exactly font problem, also you dont have to install them, you can specify font file path as blow


        if (!string.IsNullOrEmpty(_options.FontPath))
        {
            FontManager.RegisterFont(File.OpenRead(_options.FontPath));
        }

        if (!string.IsNullOrEmpty(_options.FallBackFontPath))
        {
            FontManager.RegisterFont(File.OpenRead(_options.FallBackFontPath));
        }
Document.Create(pdf =>
        {
            pdf.Page(pageHandler =>
            {
                pageHandler.If(
                    !string.IsNullOrEmpty(_options.FontName),
                    x => x.DefaultTextStyle(text => 
                        text.FontFamily(_options.FontName)
                        .Fallback(text => text.FontFamily(_options.FallBackFontName)).DirectionAuto()));

Thank @danirzv it worked.

@Zwergenpunk here I have working example of Devanagari

https://github.com/iAmBipinPaul/QuestPDF.Devanagari.Issue

Please check by last commit

thanks for the comment ;)
it helped me solved my issue:
I needed to install lato font:
apt-get -y fonts-lato