C sharp - AÑADIR VARIAS TABLAS EN C# CON ITEXTSHARP

 
Vista:
sin imagen de perfil
Val: 12
Ha aumentado su posición en 2 puestos en C sharp (en relación al último mes)
Gráfica de C sharp

AÑADIR VARIAS TABLAS EN C# CON ITEXTSHARP

Publicado por Sebastian (7 intervenciones) el 14/01/2018 16:54:04
Hola tengo 2 datagridview de una sola columna cada uno en un formulario y quiero pasarlo a un pdf con itexsharp, ya los pude pasar pero me los acomoda uno debajo del otro y yo quiero que me los ubique uno al lado de otro, alguien me podra ayudar??

adjunto el codigo que tengo hasta el momento

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
PdfPTable pdfTable = new PdfPTable(dataGridView1.ColumnCount);
PdfPTable pdfTable1 = new PdfPTable(dataGridView2.ColumnCount);
 
pdfTable.DefaultCell.Padding = 2;
pdfTable1.DefaultCell.Padding = 2;
pdfTable.WidthPercentage = 10;
pdfTable1.WidthPercentage = 10;
//pdfTable.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.DefaultCell.BorderWidth = 0;
pdfTable1.DefaultCell.BorderWidth = 0;
 
 
 
//Adding Header row
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
	PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));
	cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
 
	pdfTable.HorizontalAlignment = -2 ;
	pdfTable.AddCell(cell);
}
 
//Adding DataRow
foreach (DataGridViewRow row in dataGridView1.Rows)
{
	if (row.Cells["tres"].Value != null)
	foreach (DataGridViewCell cell in row.Cells)
	{
		pdfTable.AddCell(cell.Value.ToString());
 
	}
 
}
pdfTable.CompleteRow();
 
 
 
 
//Adding Header row
foreach (DataGridViewColumn column1 in dataGridView2.Columns)
{
	PdfPCell cell1 = new PdfPCell(new Phrase(column1.HeaderText));
	cell1.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
	pdfTable1.HorizontalAlignment = 0 ;
	pdfTable1.AddCell(cell1);
}
 
//Adding DataRow
foreach (DataGridViewRow row1 in dataGridView2.Rows)
{
	if (row1.Cells["dos"].Value != null)
		foreach (DataGridViewCell cell1 in row1.Cells)
	{
		pdfTable1.AddCell(cell1.Value.ToString());
	}
 
}
pdfTable1.CompleteRow();
 
//Exporting to PDF
string folderPath = "C:\\PDF\\";
if (!Directory.Exists(folderPath))
{
	Directory.CreateDirectory(folderPath);
}
using (FileStream stream = new FileStream(folderPath + "DataGridViewExport.pdf", FileMode.Create))
{
	Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
	PdfWriter.GetInstance(pdfDoc, stream);
	pdfDoc.Open();
	pdfDoc.Add(pdfTable);
 
	pdfDoc.Add(pdfTable1);
	pdfDoc.Close();
	stream.Close();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder