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
close icon

Bind datasource to pdfGrid

I am trying to bind a datasource to a pdf Grid in .Net Core.

I used the following code from your examples but am recieving an error on the creation of the DataTable, and its properties.

I get the following error: - 'DataTable' does not contain a constructor which takes 0 arguments.

do you have any examples for .Net Core?

//https://help.syncfusion.com/file-formats/pdf/working-with-tables
        public IActionResult PdfGrid(int paperId)
        {
            //Create a new PDF document.

            PdfDocument doc = new PdfDocument();

            //Add a page.

            PdfPage page = doc.Pages.Add();

            //Create a PdfGrid.

            PdfGrid pdfGrid = new PdfGrid();

            //Create a DataTable.
            System.Data.DataTable table = new DataTable();

            //Add columns to the DataTable
            table.Columns.Add("ID");

            table.Columns.Add("Name");

            //Add rows to the DataTable.

            table.Rows.Add(new object[] { "E01", "Clay" });

            table.Rows.Add(new object[] { "E02", "Thomas" });

            //Assign data source.
            pdfGrid.DataSource = table;

            //Draw grid to the page of PDF document.
            pdfGrid.Draw(page, new PointF(10, 10));

            //Saving the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();
            doc.Save(ms);
            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "OrderPaper.pdf";

            return fileStreamResult;
        }


1 Reply

SK Sasi Kumar Sekar Syncfusion Team January 26, 2017 11:13 AM UTC

Hi Keith, 
 
Thank you for contacting Syncfusion support. 
 
The DataTable is not compatible with the Asp.NetCore. We can add the PdfGrid values directly without using the DataTable. Please find the online documentation to directly add the values to PdfGrid. 
 
Online documentation to directly add the values to PdfGird. 
 
do you have any examples for .Net Core? 
 
Please add cell values directly using the above online documentation and let us know your feedback. 

Regards, 
Sasi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon