Column Headers Missing when Creating New PDF document using DataTable as Data Source

Dear All,

I’ve been trying to insert content extracted from a spreadsheet to a PDF document using Syncfusion PdfDocument for generating the PDF and Syncfusion XlsIO for extracting data from the spreadsheet (I am using NET 4.8 / C# and MVC5). Following the instructions regarding Working with datatables as described in the Syncfusion PDF documentation (https://help.syncfusion.com/file-formats/pdf/working-with-tables), I opted for passing a data table as data source for pdfLightTable. However, despite the values being displayed, the column headers are not added to the PDF document.

Please note that the column headers are present in the data table.

Is it possible to add column headers to the PDF file when passing a data table? If so, could you please provide some assistance how to achieve this.

I’ve attached some code demonstrating the extraction of data from the spreadsheet and how I’ve been creating the PDF document at this stage.

Thanks a mil in advance. Looking forward to your reply/ies.

Kind regards

Chris


Attachment: SampleCode_372da36a.zip

3 Replies 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team May 3, 2021 06:56 PM UTC

Hi CR, 
 
Thank you for contacting Syncfusion support.  
 
Kindly please try the PdfGrid instead of PdfLightTable to draw the table using our PDF library. Please try the below code snippet on your end and let us know if it suites your requirement. 
 
//Create a PdfGrid. 
PdfGrid pdfGrid = new PdfGrid(); 
//Assign data source. 
pdfGrid.DataSource = dataTable; 
//Draw grid to the page of PDF document. 
pdfGrid.Draw(page, new PointF(10, 10)); 
 
 
If you want to convert the excel to PDF with same table format, please refer the below link to convert Excel to PDF, 
 
Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 


Marked as answer

CR CR May 4, 2021 09:21 AM UTC

Dear Gowthamraj K, 

Thanks a mil for your reply, your suggestions and the links you kindly provided. Using PdfGrid instead of PdfLightTable did the trick, column headers are being displayed in the report.

Thanks a mil for your help.

Kind regards

Chris 


GK Gowthamraj Kumar Syncfusion Team May 4, 2021 11:10 AM UTC

Hi CR, 

Thank you for your update. We are glad to know that your problem has been solved. 

Please let us know if you need any further assistance with this. 

Regards, 
Gowthamraj K 


Loader.
Up arrow icon