Hi Cosyspro,
Thank you for contacting Syncfusion support.
1) Change default font when exporting SfDataGrid to PDF
You can change the default font by wiring the CellExporting event from DataGridPdfExportingController and setting the font for each cell, like below:
var pdfExport = new DataGridPdfExportingController(); pdfExport.CellExporting += PdfExport_CellExporting; |
var options = new DataGridPdfExportingOption(); var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, options); |
private void PdfExport_CellExporting(object? sender, DataGridCellPdfExportingEventArgs e) { if (e.CellType == ExportCellType.RecordCell) { // Example: Change to Times New Roman, size 20, bold e.PdfGridCell.Style.Font = new PdfStandardFont( PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); } } |
2) Arabic letters not displaying in PDF
For Arabic text, you need to assign a Unicode TrueType font that supports Arabic (for example, NotoNaskhArabic-Regular.ttf) instead of PdfStandardFont. You can load and apply it in the same CellExporting event:
private PdfTrueTypeFont _arabicFont; private Stream _arabicFontStream;
private void PdfExport_CellExporting(object? sender, DataGridCellPdfExportingEventArgs e) { if (e.CellType == ExportCellType.RecordCell) { EnsureArabicFont(); e.PdfGridCell.Style.Font = _arabicFont; } }
private void EnsureArabicFont() { if (_arabicFont != null) return;
var task = FileSystem.OpenAppPackageFileAsync("NotoNaskhArabic-Regular.ttf"); task.Wait(); // sync in this context
_arabicFontStream = task.Result; _arabicFont = new PdfTrueTypeFont(_arabicFontStream, 12); } |
We have attached our sample and the generated output PDF for your reference.
Please review them and let us know if you need any further assistance.
Best Regards,
Muthu Kumar Madasamy.
Attachment:
SfDataGridSample_44c65717.zip