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

PDF Export

Hello,
I'm trying to export my grid to pdf. If I take the example on documentation page it works, when I make my own grid it doesn't work. Excel export on the same page is working. My razor file is attached. Thanks, Barbara

Attachment: PdfExport_c679de01.zip

9 Replies

BS Balaji Sekar Syncfusion Team January 6, 2020 02:08 PM UTC

Hi Barbara, 
 
Greetings from Syncfusion support. 
 
Based on your query, We have prepared a sample but we are unable to reproduce the issue at our end. Please refer the below code example and sample for more information. 
 
 
            @Html.EJS().Grid<gridmvclocalization.Controllers.OrdersDetails> 
        ("Grid").DataSource((IEnumerable<object> 
    )ViewBag.dataSource).AllowPdfExport().AllowExcelExport().ToolbarClick("toolbarClick").Columns(col => 
    { 
        col.Field("OrderID").HeaderText("Order ID").Width("150").Add(); 
        col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add(); 
        col.Field("Freight").HeaderText("Freight").Width("160").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
        col.Field("ShipCountry").HeaderText("Ship Country").Width("140").Add(); 
 
    }).AllowGrouping().GroupSettings(group => { group.Columns(new string[] { "ShipCountry" }). 
    CaptionTemplate("#captiontemplate"); }).AllowPaging().Aggregates(agg=> { agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "Freight", Format = "C2", Type = "Average", GroupCaptionTemplate = "Average: ${Average}" } }).Add(); }).Toolbar(new List<string> () { "PdfExport", "ExcelExport" }).PageSettings(page => page.PageCount(2)).Render() 
             
 
<script> 
    function toolbarClick(args) { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
        if (args.item.id === 'Grid_pdfexport') { 
            gridObj.pdfExport(); 
        } 
        else if (args.item.id === 'Grid_excelexport') { 
            gridObj.excelExport(); 
        } 
    } 
</script> 
 
<script id="captiontemplate" type="text/x-template"> 
    ${field} - ${key} 
</script> 
 
 
If we misunderstood anything wrongly please get back to us with the below following details that will be helpful for us to provide better solution. 
 
  1. Share your exact requirement about your grid customization.
  2. If possible please reproduce the issue with our above attached sample.
  3. Please share your issue scenario in video demonstration.
 
Regards, 
Balaji Sekar. 



BA Barbara January 6, 2020 04:42 PM UTC

Thanks for your reply. Slovenian character seems to be the problem (č,š, ž or Č,Š, Ž). When I debug my web page I get error
Error: ArgumentOutOfRangeException:index, The character is not supported by the font.                                                        ej2.min.js:1:1787014
I'm sending You my razor file, my controller and example excel file exported from the same page. (I've added translation for columns in excel file.) Can I do something to fix this?
Thanks Barbara




Attachment: NotWorking_764175fd.zip


PK Prasanna Kumar Viswanathan Syncfusion Team January 7, 2020 11:02 AM UTC

Hi Barbara, 
 
Thanks for the update. 
 
Query#: Slovenian character seems to be the problem (č,š, ž or Č,Š, Ž) 
 
We can reproduce the same issue (Error: ArgumentOutOfRangeException:index, The character is not supported by the font.) when we export the Grid to PDF. The mentioned issue is reproduced when we used Slovenian character in grid (header, content) which is not supported by the default fonts.  
 
To change the default font of Grid header, content and caption cells in the exported document we suggest you to use ‘theme’ property of PdfExportProperties property. Please refer the below code example, sample and documentation for more information. 
 
 
@Html.EJS().Grid<gridmvclocalization.Controllers.OrdersDetails> 
        ("Grid").DataSource((IEnumerable<object> 
    )ViewBag.dataSource).AllowPdfExport().AllowExcelExport().ToolbarClick("toolbarClick").Columns(col => 
    { 
        col.Field("OžrderID").HeaderText("OžrderID").Width("150").Add(); 
        col.Field("CučstomerID").HeaderText("CučstomerID").Width("150").Add(); 
        col.Field("Freight").HeaderText("Freight").Width("160").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
        col.Field("ShipCountry").HeaderText("Ship Country").Width("140").Add(); 
 
    }).AllowGrouping().GroupSettings(group => { group.Columns(new string[] { "ShipCountry" }). 
    CaptionTemplate("#captiontemplate"); }).AllowPaging() 
    .Aggregates(agg=> { agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "Freight", Format = "C2", Type = "Average", GroupCaptionTemplate = "Average: ${Average}" } }).Add(); }) 
        .Toolbar(new List<string> 
            () { "PdfExport", "ExcelExport" }).PageSettings(page => page.PageCount(2)).Render() 
            ) 
</div> 
 
<script> 
    function toolbarClick(args) { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
        if (args.item.id === 'Grid_pdfexport') { 
            let pdfExportProperties = { 
                theme: { 
                    header: { font: new ej.pdfexport.PdfTrueTypeFont(adventProFont, 12) }, 
                    caption: { font: new ej.pdfexport.PdfTrueTypeFont(adventProFont, 10) }, 
                    record: { font: new ej.pdfexport.PdfTrueTypeFont(adventProFont, 9) } 
                } 
            }; 
            gridObj.pdfExport(pdfExportProperties); 
        } 
        else if (args.item.id === 'Grid_excelexport') { 
            gridObj.excelExport(); 
        } 
    } 
var adventProFont = 'AAEAAAARAQAABAAQRFNJRwAAAAEAALa8AAAACEZGVE1fekHUAACnZAAAABxHREVGACgBwQAAp4AAAA………………………………………………………………………………………………………………………' 
</script> 
 
<script id="captiontemplate" type="text/x-template"> 
    ${field} - ${key} 
</script> 
 
 
 
 
Regards, 
Prasanna Kumar N.S.V 
 



BA Barbara January 7, 2020 02:30 PM UTC

Thanks, it worked  :)  Barbara


PK Prasanna Kumar Viswanathan Syncfusion Team January 7, 2020 05:38 PM UTC

Hi Barbara, 
 
We are happy to hear that the provided solution has been working fine. 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Prasanna Kumar N.S.V 



AN Anushree Nagore June 19, 2020 10:37 AM UTC

PDF export does not work properly on firefox. browser, when I use custom font.(pdfTrueTypeFont). It exports blank pdf.


PK Prasanna Kumar Viswanathan Syncfusion Team June 22, 2020 09:56 AM UTC

Hi Barbara, 
 
Thanks for the update. 
 
Based on your query you have mentioned that the PDF Exporting is not working fine with the firefox browser when using the custom font (PdfTrueTypeFont). We checked the previous attached sample with the firefox and the PDF exporting has been working fine at our end. 
 
For your convenience we have attached the video and please download the video from the following link 
 
 
To find the root cause of an issue, we need the following details 
 
1. Share the complete Grid code example. 
 
2. Share the video demonstration of an issue. 
 
3. Have you faced any script error while exporting to PDF? If yes, share the screenshot and stackrace of an issue. 
 
4. If possible please replicate the issue in the previous attached sample. 
 
5. Share the firefox browser version. 
 
Note: We checked in firefox browser version 72.0.2 
 
Regards, 
Prasanna Kumar N.S.V 



BA Barbara June 22, 2020 10:06 AM UTC

Your answer on January resolved my problem, thanks.
Anushree Nagore has now a problem not me. Best regards Barbara


AG Ajith Govarthan Syncfusion Team June 23, 2020 02:58 PM UTC

Hi Anushree Nagore, 

Sorry for the inconveniences. 

We have requested the some details  on June 22, 2020 09:56 AM UTC to validate the issue at our end and we also shared the video demonstration of the issue. So please share the requested details to validate further on your requirement. 

Regards, 
Ajith G. 


Loader.
Up arrow icon