PDF Export,

Hello,
when testing the grid, I've encountered a behavior I'm not able to fix myself.

When a grid column has HeaderText containing e.g. ž,š,č,ř or similar character, I get following error in my console:

ArgumentOutOfRangeException:index, The character is not supported by the font.

I've tried to change the fonts following this example:
https://ej2.syncfusion.com/aspnetmvc/documentation/grid/pdf-export/#default-fonts-for-pdf-exporting

But it did not help. Moreover, Helvetica, the default font should support these characters.

Could you, please, suggest some solution?
Thank you,
Petr

5 Replies

RR Rajapandi Ravi Syncfusion Team May 13, 2020 09:59 AM UTC

Hi Petr, 

Greetings from syncfusion support 

We checked the attached error and the error indicates that the text used in grid (header) is not supported by the default fonts. So you can change the default font of Grid header, content and caption cells in the exported document by using ‘theme’ property of PdfExportProperties property.  

Please refer the below code example, sample and documentation for more information. 

 
<div class="control-section"> 
    @( 
            @Html.EJS().Grid<gridmvclocalization.Controllers.OrdersDetails> 
        ("Grid").DataSource((IEnumerable<object> 
    )ViewBag.dataSource).AllowPdfExport().AllowExcelExport().ToolbarClick("toolbarClick").Columns(col => 
    { 
        col.Field("OžrderID").HeaderText("OžrderID").Width("150").Add(); 
        col.Field("CučstomerID").HeaderText("CučstomerID").Width("150").Add(); 
        col.Field("Freight").HeaderText("Freight").Width("160").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
        col.Field("ShipCountry").HeaderText("Ship Country").Width("140").Add(); 
 
    }).AllowPaging().Toolbar(new List<string>() { "PdfExport", "ExcelExport" }).PageSettings(page => page.PageCount(2)).Render()) 
</div> 
 
<script> 
    function toolbarClick(args) { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
        if (args.item.id === 'Grid_pdfexport') { 
            let pdfExportProperties = { 
                theme: { 
                    header: { font: new ej.pdfexport.PdfTrueTypeFont(adventProFont, 12) }, 
                    caption: { font: new ej.pdfexport.PdfTrueTypeFont(adventProFont, 10) }, 
                    record: { font: new ej.pdfexport.PdfTrueTypeFont(adventProFont, 9) } 
                } 
            }; 
            gridObj.pdfExport(pdfExportProperties); 
        } 
        else if (args.item.id === 'Grid_excelexport') { 
            gridObj.excelExport(); 
        } 
    } 
    var adventProFont = 'AAEAAAARAQAABAAQRFNJRwAAAAEAALa8AAAACEZGVE1fekHUAACnZAAAABxHREVGACgBwQAAp4AAAA………………………………………………………………………………………………………………………' 
 
</script> 



Regards, 
Rajapandi R 



PE Petr May 24, 2020 08:41 PM UTC

Dear Rajapandi,

Thank you very much for your help - the solution you provided has helped me to find my mistake.

I have one follow-up question - is it possible to set this up globally? 
E.g. to replace the base64 string for default Helvetica font used for exports? 
I basically need to support the same thing for all the pdf exports in my solution.

Thank you for your help.

Best regards,
Petr


AG Ajith Govarthan Syncfusion Team May 25, 2020 09:05 AM UTC

Hi Petr, 

Thanks for the update. 

Query:  is it possible to set this up globally? 

From the query we suspect that you want to use the font globally for all the files. For this you can store the base64 font in a separate file javascript and you can refer and use them as per you need. 

Please get back to us if you need further assistance. 

Regards, 
Ajith G 



PE Petr May 25, 2020 10:10 AM UTC

Ok, let me rephrase my question. 
In my solution, where can I find the base64 strings for default fonts, which are listed here?
https://ej2.syncfusion.com/aspnetmvc/documentation/grid/pdf-export/?no-cache=1#default-fonts-for-pdf-exporting

Best regards,
Petr


BS Balaji Sekar Syncfusion Team May 26, 2020 07:47 AM UTC

Hi Petr, 
 
Query:  where can I find the base64 strings for default fonts, which are listed here? 
 
We can used the default fonts in the pdfExport file using pdfFontFamily module of pdfexport instead of base64 string. In below code example, we have achieved your requirement in pdf exporting. 
[index.cshtml] 
 
<script>  
    function toolbarClick(args) {  
        var gridObj = document.getElementById("Grid").ej2_instances[0];  
        if (args.item.id === 'Grid_pdfexport') {  
            let pdfExportProperties = {  
                theme: {  
                    header: { font: new ej.pdfexport.PdfStandardFont(new ej.pdfexport.PdfFontFamily.Helvetica, 12, new ej.pdfexport.PdfFontStyle.Bold) },  
                    caption: { font: new ej.pdfexport.PdfStandardFont(new ej.pdfexport.PdfFontFamily.Helvetica, 10) },  
                    record: { font: new ej.pdfexport.PdfStandardFont(new ej.pdfexport.PdfFontFamily.Helvetica, 9) }  
                }  
            };  
            gridObj.pdfExport(pdfExportProperties);  
        }  
        else if (args.item.id === 'Grid_excelexport') {  
            gridObj.excelExport();  
        }  
    }  
 
 
If you want to use default font in base64 string, please find the below steps to get the base64 format font file then you can use that file to pdf export using below documentation. 
 
  1. Download TTF file for the corresponding (custom (which font support the - symbol) font (https://www.fontsquirrel.com/fonts/list/language/thai )
  2. Then convert the TTF file into base64 string (https://www.giftofspeed.com/base64-encoder/).
  3. Finally apply the base64 string to pdfTrupetypeFont.
 

Please get back to us, if you need further assistance. 

Regards, 
Balaji Sekar 


Loader.
Up arrow icon