Need to make pdf data format as data appear in the grid

In my blazor data grid I have template column "Code" I use function in Template tag to appear it like this "NXT٦٥٤٣K" but when make pdf export it shown as "NXT6543K" so how to solve this problem.

this is the function: 

public static string FormatNumber(string number)

{

if (numberFormat == "EN") return number;

var arabicDigits = new[] { '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩' };

var result = string.Concat(number.Select(c => char.IsDigit(c) ? arabicDigits[c - '0'] : c));

return result;

}


1 Reply

NP Naveen Palanivel Syncfusion Team September 15, 2025 09:51 AM UTC

Hi Ahmed Eldamity,


Greeting from syncfusion,

Based on your query we would like to inform that ,when using grid column templates, you need to set IncludeTemplateColumn to true to export template values and you must handle cell content in the PdfQueryCellInfoEvent to achieve this behavior. Without utilizing the PdfQueryCellInfoEvent, values will be exported based solely on the field definitions. This is the default behavior.

Also, we have provided support for very few of the fonts to exported to PDF format. So, to export Arabic or any other language letters(True type font) to PDF format, we need to set True Type font information as base64 string to FontFamily of PdfGridFont. We have provided support for PdfTrueTypeFont in ExportToPdfAsync () method.  Using this we can export the different font to pdf format from Grid. Please apply your corresponding custom TTF as base64 string for the FontFamily. We can achieve arabic text in column value by giving Theme. Record = RecordThemeStyle.

UG : https://blazor.syncfusion.com/documentation/datagrid/pdf-export-options#add-custom-font

   <GridEvents PdfQueryCellInfoEvent="PdfQueryCellInfoHandler" TValue="dtoParentWise"></GridEvents>

    <GridColumns>

        <GridColumn Field=@nameof(dtoParentWise.AccountCode) HeaderText="Parent Code" Width="130"></GridColumn>

        <GridColumn Field=@nameof(dtoParentWise.ParentName) HeaderText="Parent Name" Width="100"></GridColumn>

        <GridColumn HeaderText="Code" Width="130">

 

            <Template>

                @{

                    var formatted = FormatNumber((context as dtoParentWise).CountOfStudents.ToString());

                }

                <text>@($"NXT{formatted}K")</text>

            </Template>

 

        </GridColumn>

    </GridColumns>

</SfGrid>

 

@code {

    public SfGrid<dtoParentWise>? PGrid { get; set; }

    public List<dtoParentWise>? ParentWiseList = new List<dtoParentWise>();

    public string numberFormat = "AR"; // Change to "EN" for English digits

    public static string FormatNumber(string number)

    {

        var arabicDigits = new[] { '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩' };

        var result = string.Concat(number.Select(c => char.IsDigit(c) ? arabicDigits[c - '0'] : c));

        return result;

    }

 

    public void PdfQueryCellInfoHandler(PdfQueryCellInfoEventArgs<dtoParentWise> args)

    {

        if (args.Column.HeaderText == "Code")

        {

            string formatted = FormatNumber(args.Data.CountOfStudents.ToString());

            args.Cell.Value = $"NXT{formatted}K";

        }

    }

 

    public async Task save_Click()

    {

 

        PdfExportProperties ExportProperties = new PdfExportProperties();

        ExportProperties.IncludeTemplateColumn = true;

        PdfTheme Theme = new PdfTheme();

        PdfThemeStyle RecordThemeStyle = new PdfThemeStyle()

            {

                FontSize = 17,

                Font = new PdfGridFont() { IsTrueType = true, FontSize = 17, FontFamily = "AAEAAAAOAIAAAwBgRFNJ……
                    };

    Theme.Record = RecordThemeStyle;

    ExportProperties.Theme = Theme;

    await this.PGrid.ExportToPdfAsync(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/czech  )
  2. Then convert the TTF file into base64 string (https://www.giftofspeed.com/base64-encoder/).
  3. Finally apply the base64 string to pdfTrupetypeFont


We also attached the sample and screenshot for your reference.



Regards,

Naveen


Attachment: BlazorApp11_PDF_eec4f551.zip

Loader.
Up arrow icon