We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Font Awesome in PDF documents

Is there any way of adding a font awesome character to a table cell ? or anywhere really.

regards
Martin

1 Reply

SL Sowmiya Loganathan Syncfusion Team October 18, 2019 05:06 AM

Hi Martin, 

Thank you for contacting Syncfusion support. 

We can achieve your requirement of “Add font awesome characters to a table cell” using the font file “fontawesome-webfont.ttf”. Please refer the below code snippet for more details, 

//Create a new PDF document 
PdfDocument document = new PdfDocument(); 
 
//Add a page 
PdfPage page = document.Pages.Add(); 
 
//Create font 
FileStream fontFileStream = new FileStream("fontawesome-webfont.ttf", FileMode.Open, FileAccess.Read); 
PdfFont font = new PdfTrueTypeFont(fontFileStream, 14); 
 
//Create a PdfGrid 
PdfGrid pdfGrid = new PdfGrid(); 
 
//Create a DataTable 
DataTable dataTable = new DataTable(); 
 
//Add columns to the DataTable 
dataTable.Columns.Add("Font Name"); 
dataTable.Columns.Add("Awesome Character"); 
 
//Add rows to the DataTable 
dataTable.Rows.Add(new object[] { "fontawesome-webfont", "\uf02d" }); 
 
//Assign data source 
pdfGrid.DataSource = dataTable; 
 
//Add cell style 
PdfGridCellStyle cellStyle = new PdfGridCellStyle(); 
cellStyle.Font = font; 
pdfGrid.Rows[0].Cells[1].Style = cellStyle; 
 
//Draw grid to the page of PDF document 
pdfGrid.Draw(page, new PointF(10, 10)); 
 
//Save the document 
MemoryStream stream = new MemoryStream(); 
document.Save(stream); 
document.Close(true); 


Please find the .ttf file downloaded link from below, 

Please try the above code snippet in your end and let us know the result. 

Regards, 
Sowmiya Loganathan 
 


Loader.
Live Chat Icon For mobile
Up arrow icon