Fonts in PDFGrid
Hi,
I'm exporting data from a Syncfusion Datagrid into a PDF file.
Everything goes OK but I can't change the fonts of all rows/columns, except Headers.
Even using "pdfgrid.style.font" does not change the rows/columns/cells font.
How can I proceed with this?
I appreciate any help.
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
SL
Sowmiya Loganathan
Syncfusion Team
August 21, 2020 04:03 AM UTC
Hi DavidBS,
Thank you for contacting Syncfusion support.
We have analyzed your requirement “Change the fonts for rows/Column/cell in PDF grid” and this can be achieved by using below code snippet,
Change the font for particular row:
UG link: https://help.syncfusion.com/file-formats/pdf/working-with-tables#row-customization-in-pdfgrid
|
//Create an instance of PdfGridRowStyle
PdfGridRowStyle pdfGridRowStyle = new PdfGridRowStyle();
pdfGridRowStyle.Font = new PdfStandardFont(PdfFontFamily.Courier, 15, PdfFontStyle.Bold);
//Set style for the PdfGridRow
pdfGrid.Rows[0].Style = pdfGridRowStyle; |
Change the font for particular cell:
UG link: https://help.syncfusion.com/file-formats/pdf/working-with-tables#cell-customization-in-pdfgrid
|
//Specify the style for the PdfGridCell
PdfGridCellStyle pdfGridCellStyle = new PdfGridCellStyle();
pdfGridCellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20, PdfFontStyle.Italic);
//Apply style
PdfGridCell pdfGridCell = pdfGrid.Rows[1].Cells[0];
pdfGridCell.Style = pdfGridCellStyle; |
Change the font for particular column using BeginCellLayout event handler:
UG link: https://help.syncfusion.com/file-formats/pdf/working-with-tables#columns-customization-in-pdfgrid
|
private static void PdfGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
//Change the font style for Column 1
if(!args.IsHeaderRow && args.CellIndex==1)
{
args.Style.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 0, PdfFontStyle.Underline);
}
} |
We have created the sample to illustrate the same. Please find the download link from below,
Please try the above sample in your end and let us know the result.
Regards,
Sowmiya Loganathan
DA
DavidBS
August 21, 2020 05:46 PM UTC
:D
Thank you again Sowmiya!
The last solution based on the event functioned like a charm. Interesting notice that the documentation is based on the PDFLightTable and because of this I didn't realize it could be done with PDFGrid (which I utilize to export Datagrid to PDF format).
You're really bad!
Warm hugs and have a very nice weekend.
SL
Sowmiya Loganathan
Syncfusion Team
August 24, 2020 10:08 AM UTC
Hi DavidBS,
Thank you for the update.
The documentation for PDF table contains both PdfGrid and PdfLightTable. Please refer the below documentation for your reference,
However, please let us know if you want to export DataGrid to PDF, it will helpful for us to provide the solution on this.
Regards,
Sowmiya Loganathan
Marked as answer
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
DA DavidBS
- Aug 19, 2020 05:35 PM UTC
- Aug 24, 2020 10:08 AM UTC