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

Transform a collection of data into pdf

How to transform a collection of data into pdf using the PdfDocument and/or PDF Viewer components
I have:
var dataReport = new object ();
dataReport = (from c in ctxt.vwDefrayalAndItems
                                           where c.ID.Equals (ReportId)
                                           select c) .ToArray ();



1 Reply

SL Sowmiya Loganathan Syncfusion Team July 11, 2019 08:31 AM UTC

Hi Edvaldo, 

Thank you for contacting Syncfusion support. 

We can convert collection of data into PDF using PdfGrid. Please refer the below code snippet for more details, 

//Create a new PDF document 
PdfDocument doc = new PdfDocument(); 
 
//Add a page 
PdfPage page = doc.Pages.Add(); 
 
//Create a PdfGrid 
PdfGrid pdfGrid = new PdfGrid(); 
 
//Add values to list 
List<object> data = new List<object>(); 
Object row1 = new { ID = "1", Name = "Clay" }; 
Object row2 = new { ID = "2", Name = "Gray" }; 
Object row3 = new { ID = "3", Name = "Ash" }; 
 
data.Add(row1); 
data.Add(row2); 
data.Add(row3); 
 
//Add list to IEnumerable 
IEnumerable<object> tableData = data; 
 
//Assign data source 
pdfGrid.DataSource = tableData; 
 
//Draw grid to the page of PDF document 
pdfGrid.Draw(page, new PointF(10, 10)); 
 
//Save the document 
doc.Save("Sample.pdf"); 
 
//close the document 
doc.Close(true); 


Kindly check with the above link, code snippet and let us know if it satisfies your requirement. If not please provide us further details about your requirement. It will helpful for us to provide the precise solution on this.  

Regards, 
Sowmiya L 


Loader.
Live Chat Icon For mobile
Up arrow icon