Answer:
<SfGrid DataSource="@list" ID="grid" Toolbar="@(new List<string>() { "PdfExport" })" AllowPdfExport="true" @ref="grid"> <GridEvents OnToolbarClick="ToolbarClick" TValue="EmployeeData">GridEvents> ... SfGrid>
public async Task ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args) { PdfExportProperties ExportProperties = new PdfExportProperties(); PdfTheme Theme = new PdfTheme();
PdfThemeStyle HeaderThemeStyle = new PdfThemeStyle() { Font = new PdfGridFont { IsTrueType = true, FontSize = 8, FontFamily = "T1RUTwA..." }, //apply your custom font base64 string to FontFamily 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..." }, //apply your custom font base64 string to FontFamily FontColor = "#64FA50", FontName = "Calibri", FontSize = 17
}; Theme.Record = RecordThemeStyle;
PdfThemeStyle CaptionThemeStyle = new PdfThemeStyle() { Font = new PdfGridFont { IsTrueType = true, FontSize = 8, FontFamily = "T1RUT...ABQ=" }, //apply your custom font base64 string to FontFamily FontColor = "#64FA50", FontName = "Calibri", FontSize = 17, Bold = true
}; Theme.Caption = CaptionThemeStyle;
ExportProperties.Theme = Theme; await this.grid.PdfExport(ExportProperties); }
|
To use the custom font base64 string in an application. Follow the below steps to get the base64 string for the custom font.
Hi,
Thank you for the help.
The font problem is partially solved as
محمد
will be presented as
د م ح م
i.e the letters are in reverse order without any concatenation
Best regards,
AM
I found solution: (i am using blazor server side package v20.2.0.48)
embed your fonts as Resource in your project you can use any true type font that support right-to-left languages
then code:
PdfExportProperties Props = new PdfExportProperties(); Props.BeginCellLayout = new PdfGridBeginCellLayoutEventHandler(BeginCellEvent); Grid.ExportToPdfAsync(Props);
and this:
MemoryStream Stream = new MemoryStream(Properties.Resources.XBZar);
private void BeginCellEvent(object sender, PdfGridBeginCellLayoutEventArgs args)
{
args.Style = new PdfGridCellStyle()
{
Font = new PdfTrueTypeFont(Stream, 10, PdfFontStyle.Regular),
StringFormat = new PdfStringFormat()
{
TextDirection = PdfTextDirection.RightToLeft
}
};
}
done!
Hi Mahdi,
Thanks for reaching Syncfusion support again.
We appreciate you for taking time to informing us.
Please get back to us if you have any further queries.
Regards,
Sarveswaran PK
Hi Meysam,
Thank you for reaching out to us with your question regarding embedding a font as a resource in your project.
Mahdi has provided a solution that involves storing the font in a resource file and accessing it using a MemoryStream. Then font is then used in the BeginCellLayout property of the PdfExportProperties.
If you are encountering any issues with this approach, please share the following details with us:
This information will be extremely helpful in resolving your issue as quickly and efficiently as possible.
Please don't hesitate to reach out to us if you have any further questions or concerns. We are here to help.
Best regards,
Vignesh Natarajan