Add tables to the pdf

Hello i want to create tables in a uwp c# project ben when i look at the sample 'Working with tables' it goes wrong at the line

i got the error 'DataTable' does not contain a constructor that takes 0 arguments!!

what i'm doing wrong?

DataTable table = new DataTable();

1 Reply

SP Sathya Ponnusamy Syncfusion Team January 22, 2018 09:30 AM UTC

Hi Adrie, 

Thank you for contacting Syncfusion support. 

The DataTable is not supported in UWP platform. We suggesting you to use IEnumerable as Data source in UWP project as provided in the code snippetPlease find the below code snippet for more details :   

//Create the pdfdocument   
PdfDocument document = new PdfDocument();  
  
//Add the page  
PdfPage page = document.Pages.Add();  
  
//Get product  
IEnumerable collection = GetProducts();  
  
// Create a PdfGrid.   
PdfGrid pdfGrid = new PdfGrid();  
  
//Assign data source.  
pdfGrid.DataSource = collection;  
  
//Draw PdfGrid.  
pdfGrid.Draw(page, new PointF(30, 70));  
  
//Sample for adding rows manually  
PdfGrid table = new PdfGrid();  
table.Columns.Add(3);  
  
PdfGridRow row1 = table.Rows.Add();  
row1.Cells[0].Value = "Column 1";  
row1.Cells[1].Value = "Column 2";  
row1.Cells[2].Value = "Column 3";  
  
// Draw PdfGrid  
table.Draw(page, new PointF(30, 150));  
  
//Save and close the document.  
MemoryStream stream = new MemoryStream();  
document.Save(stream);  
  
private List<Product> GetProducts()  
{  
List<Product> collection = new List<Product>();  
  
Product product = new Product();  
  
//Add Row values  
product.Name = "Computer";  
product.Description = "Computer";  
product.Quantity = "12";  
  
//Add Row values  
collection.Add(product);  
  
product = new Product();  
product.Name = "Mobile";  
product.Description = "Android Mobile";  
product.Quantity = "34";  
  
//Add Row values  
collection.Add(product);  
product = new Product();  
product.Name = "Ipod";  
product.Description = "Apple";  
product.Quantity = "12";  
  
collection.Add(product);  
  
return collection;  
}  


Please find the sample from the below link: 

Regards, 
Sathya 


Loader.
Up arrow icon