I am exporting a Datagrid
to PDF with iTextSharp
. Everything works fine, but I need to give the space of an entire row to a data that is long.
For example:
Record 1: id= 1, name ="Pedro", last name ="Perez", description= "This is the description of pedro and it is very long".
I need id
, nombre
and apellido
to be in row 1, and in the row below is the description. So with all the records that make up the table! Does anyone have an idea how to do that?
I want PartFound to be below the first record (and occupy the entire column)
Without knowing your code of how you export your data to PDF it is difficult to help you as you intend, however I had a similar situation as the one you have and I obtained the solution, I clarify that my case was with
Windows Form
andDataGridView
but using the libraryiTextSharp
.From the outset I think the way it was solved can help you a bit (if I understood what you require), I don't think it's the best solution but it does solve the problem and I'll share it with you.
Basically what I do is get the columns of my datagridview (in this case there are 11, adapting to the data of your problem). With
I am defining the width of each column and if you notice the last one I put a zero (0), this is because in the first instance, we only want to show the data of the first 10 columns and the last column that is not visible.
With
PdfPCell
we declare a cell that prints all the columns (in this case of my dgv) In fact it prints up to column 11 but since the last one has a width of 0 the data is not visibleAt last we compare that if the column is 10 (remember that the for loop starts from 0) then a new cell is created again and the data from column 11 is stored there, which in your example would be "PartFound" , We combine all the columns as if it were an excel with the instruction
celda1.Colspan = 11;
and with that you get a result as shown in the image.
Attached the complete code.