This is a migrated thread and some comments may be shown as answers.

Export to pdf with Gill Sans MT

3 Answers 256 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Travis
Top achievements
Rank 1
Travis asked on 01 Jul 2014, 09:39 AM
Hi All,

I have a radgrid, I set the  <MasterTableView Font-Names="Gill Sans MT"  >. I also set the style as

<style type="text/css">
    .rgMasterTable
    {
        font-family: Gill Sans MT !important;
    }
</style>

in web browser my Grid is showing the correct font (Gill Sans MT) and export to excel also showing correct font. But when I export it to pdf, it is not exporting in the Gill Sans MT font.  I also tried to set the

 <ExportSettings>
                    <Pdf DefaultFontFamily="Gill Sans MT" />
                </ExportSettings>

But still no luck. then I tried from code-behind as

 protected void btnpdfCard_Click(object sender, ImageClickEventArgs e)
    {
             
        foreach (GridDataItem item in rgExportGrid.Items)
        {
            item.Style["font-family"] = "Gill Sans MT";
            item.Style["font-size"] = "6px";
        }
rgExportGrid.MasterTableView.ExportToPdf();
}

but still no luck to export with Gill Sans MT font. Can anyone let me know where I am wrong?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Jul 2014, 10:31 AM
Hi Travis,

Please try the following code snippet to apply styles on export to PDF.

C#:
bool IsExport = false;
protected void PDFbtn_Click(object sender, EventArgs e)
{
    IsExport = true;
    RadGrid1.ExportSettings.OpenInNewWindow = true;
    RadGrid1.ExportSettings.IgnorePaging = true;
    RadGrid1.MasterTableView.ExportToPdf();
}
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (IsExport)
    {
        ApplyStylesToPDFExport(e.Item);
    }
}
private void ApplyStylesToPDFExport(GridItem item)
{
    if (item is GridHeaderItem)
    foreach (TableCell cell in item.Cells)
     {
        cell.Style["font-family"] = "Gill Sans MT";
     }
    if (item is GridDataItem)
    {
        item.Style["font-size"] = "6px";
        item.Style["font-family"] = "Gill Sans MT";
    }
}

Thanks,
Princy
0
Travis
Top achievements
Rank 1
answered on 02 Jul 2014, 05:24 AM
Hi Princy,

Thanks for your replying, but this trick did not work for me. Still exporting pdf in times new roman instead of Gill Sans MT.

Any other tip please?

0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Jul 2014, 06:29 AM
Hi Travis,

The above code works fine. Try to change the font-family and check, as I checked with other fonts it worked fine. The issue is not with code,I guess the Gill Sans MT is not supported in PDF. Please check the supported fonts for PDF and try the code again.

Thanks,
Princy
Tags
Grid
Asked by
Travis
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Travis
Top achievements
Rank 1
Share this question
or