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

DataGridView to PdfLightTable

Hello,

I have a datagridview that I would like to export to PDF. Do you have any examples of doing this? In particular I would like to know how to change the width of the PdfLightTable based on the printed size of the items in the bound DataTable.

Also, I there is a sample that is mentioned here: http://www.syncfusion.com/forums/89709/pdflighttable-column-width that is no longer available. Is there an updated version somewhere?

Thank you in advance


6 Replies

KC Karthikeyan Chandrasekar Syncfusion Team July 21, 2014 12:35 PM UTC

Hi Jonathan,

Thank you for your interest in Syncfusion Products.

 

We can able to export datagridview to PdfLightTable, and setting of the column width is mentioned in the attached sample. For finding the maximum width of the column we have to manually calculate the size of each row(value) in the column and find the maximum width of the column. Please refer this and let us know if you have any concern.

PdfLightTable.zip

Thanks,

Karthikeyan.C



JR Jonathan Reis July 21, 2014 02:08 PM UTC

Hello Karthikeyan,
thank you for the response. Then sample you gave shows how to use a DataTable instead of a DataGridView. A DataTable does not contain formatting information.

1) Calculate the width of the column in the PdfLightTable based on:
   a) The width of the column in the DataGridView. Do PdfLightTable and DataGridView share the same units for: Column.Width.
   b) The width of the text to be displayed in the PdfLightTable

2) Have all columns in the PdfLightTable fit on a single page. Or,

3) Have the text within a row wrap.



 


JR Jonathan Reis July 21, 2014 02:10 PM UTC

I forgot to mention my DataGridView is not bound to a DataTable and it can contain quite a few rows, so I would prefer if I didn't have to first export my DataGridView to a DataTable before exporting.


KC Karthikeyan Chandrasekar Syncfusion Team July 23, 2014 11:53 AM UTC

Hi Jonathan,

Thank you for your information.

 

We can able to achieve your requirement by using Grid Control. Instead of using DataGridView and manually convert to PDF document, Grid control will automatically export your grid to the PDF document with the styles and String Format. I have attached a sample for using grid control, please let us know if this meets your requirements or let us know if you have any concern.

GridToPDF.zip

Thanks,

Karthikeyan.C



JR Jonathan Reis July 28, 2014 03:37 AM UTC

You have not answered any of my questions. Let me repeat them below in case you have missed them.

How do I?

1) Calculate the width of the column in the PdfLightTable based on:
   a) The width of the column in the DataGridView. Do PdfLightTable and DataGridView share the same units for: Column.Width.
   b) The width of the text to be displayed in the PdfLightTable

2) Have all columns in the PdfLightTable fit on a single page. Or,

3) Have the text within a row wrap.





KC Karthikeyan Chandrasekar Syncfusion Team July 30, 2014 03:03 AM UTC

Hi Jonathan,

Thank you for your update.

 

We can set the width of the column of the DataGridView, however as DataGridView is in pixels we have to convert to points, please use the below code snippet.

            PdfUnitConvertor unitConv = new PdfUnitConvertor();

            tblPDF.Columns[0].Width = unitConv.ConvertFromPixels(dataGridView1.Columns[0].Width+100, PdfGraphicsUnit.Point);

 

If there is enough space present is a single page then the PdfLightTable will draw within a Page, or else it will automatically paginate to the next page. And the text within the row will wrap automatically.

 

Please let us know if you have any concern.

Thanks,

Karthikeyan.C


Loader.
Live Chat Icon For mobile
Up arrow icon