Pdf export with accented characters

Hi, 

I try to export the grid to pdf, but I got this error message:

Uncaught (in promise) Error: ArgumentOutOfRangeException:index, The character is not supported by the font.

I tried a workaround and specify the font, but if I embed the font in base64, then only the headers are filled, the data rows are empty in the pdf.

I use WebAssembly on client side.

My code:

@page "/"

@using Syncfusion.Blazor.Grids

<SfGrid DataSource="@list" ID="grid" Toolbar="@(new List<string>() { "PdfExport" })"
        AllowPdfExport="true"
        @ref="grid">
    <GridEditSettings Mode="EditMode.Dialog" AllowAdding="true"
                      AllowDeleting="true" AllowEditing="false" />
    <GridEvents OnToolbarClick="ToolbarClick" TValue="EmployeeData"></GridEvents>
    <GridColumns>
        <GridColumn HeaderText="Id" Field=@nameof(EmployeeData.Id) IsPrimaryKey="true" />
        <GridColumn HeaderText="FirstName" Field=@nameof(EmployeeData.FirstName) />
    </GridColumns>
</SfGrid>

@code {
    public class EmployeeData
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string Designation { get; set; }
        public string eTag { get; set; }
    }

    public List<EmployeeData> list = new List<EmployeeData>()
{
        new EmployeeData{ Id=1, FirstName="Árvíztűrő tükörfúrógép", Designation="None", eTag="W/\"datetime'2020-05-31T18:53:18.21Z'\"" },
        new EmployeeData{ Id=2, FirstName="Andy", Designation="None", eTag="W/\"datetime'2020-05-31T18:55:18.21Z'\"" },
    };

    public SfGrid<EmployeeData> grid { get; set; }

    public async Task ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args)
    {
        await this.grid.PdfExport();
    }

}

Regards,
 Peter


1 Reply

RS Renjith Singh Rajendran Syncfusion Team June 4, 2020 08:03 AM UTC

Hi Németh, 

Greetings from Syncfusion support. 

To export Croatian letters(True type font), we need to set True Type font information as base64 string to FontFamily of PdfGridFont. Grid have we have support for PdfTrueTypeFont in PdfExport method. We have prepared a sample based on this, please download the sample from the link below, 

Please use the codes in your application based on your needs, 

public async Task ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args) 
{ 
    PdfExportProperties ExportProperties = new PdfExportProperties(); 
    ExportProperties.FileName = "text.pdf"; 
    ExportProperties.ExportType = ExportType.AllPages; 
    PdfTheme Theme = new PdfTheme(); 
 
    PdfBorder HeaderBorder = new PdfBorder(); 
    HeaderBorder.Color = "#64FA50"; 
 
    PdfThemeStyle HeaderThemeStyle = new PdfThemeStyle() 
    { 
        Font = new PdfGridFont { IsTrueType = true, FontSize = 8, FontFamily = "T1RUTwA..." }, 
        FontColor = "#64FA50", 
        FontName = "Calibri", 
        FontSize = 17, 
        Bold = true, 
        Border = HeaderBorder 
    }; 
    Theme.Header = HeaderThemeStyle; 
 
    PdfThemeStyle RecordThemeStyle = new PdfThemeStyle() 
    { 
 
        Font = new PdfGridFont { IsTrueType = true, FontSize = 8, FontFamily = "T1RUTwALAI..." }, 
        FontColor = "#64FA50", 
        FontName = "Calibri", 
        FontSize = 17 
 
    }; 
    Theme.Record = RecordThemeStyle; 
 
    PdfThemeStyle CaptionThemeStyle = new PdfThemeStyle() 
    { 
        Font = new PdfGridFont { IsTrueType = true, FontSize = 8, FontFamily = "T1RUT...ABQ=" }, 
        FontColor = "#64FA50", 
        FontName = "Calibri", 
        FontSize = 17, 
        Bold = true 
 
    }; 
    Theme.Caption = CaptionThemeStyle; 
 
    ExportProperties.Theme = Theme; 
    await this.grid.PdfExport(ExportProperties); 
} 
 
 

Note : We request you to use the corresponding custom font base64 string in your application, based on your requirement. Please follow the below steps to get the base64 string for the custom font. 
  1. Download TTF file for the corresponding (custom) font (https://www.fontsquirrel.com/fonts/list/language/croatian )
  2. Then convert the TTF file into base64 string (https://www.giftofspeed.com/base64-encoder/).
  3. Finally apply the base64 string to FontFamily of PdfGridFont.

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 




Loader.
Up arrow icon