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.
Unfortunately, activation email could not send to your email. Please try again.

DataGridView to PdfLightTable

Thread ID:

Created:

Updated:

Platform:

Replies:

117015 Jul 19,2014 06:49 PM Jul 29,2014 11:03 PM Windows Forms 6
loading
Tags: PDF
Jonathan Reis
Asked On July 19, 2014 06:49 PM

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


KarthikeyanC [Syncfusion]
Replied On July 21, 2014 08:35 AM

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


Jonathan Reis
Replied On July 21, 2014 10:08 AM

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.



 

Jonathan Reis
Replied On July 21, 2014 10:10 AM

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.

KarthikeyanC [Syncfusion]
Replied On July 23, 2014 07:53 AM

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


Jonathan Reis
Replied On July 27, 2014 11:37 PM

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.




KarthikeyanC [Syncfusion]
Replied On July 29, 2014 11:03 PM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;