Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space between two tables in iTextSharp

Tags:

c#

winforms

itext

Just as the title says, I'm using iTextSharp to generate a report. And I want to add a space between two tables, but I don't know how.

this is my code:

var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
PdfPTable table1 = new PdfPTable(2);
table1.WidthPercentage = 25;
table1.HorizontalAlignment = Element.ALIGN_LEFT;
table1.AddCell(new PdfPCell(new Paragraph("Factura No: ")));
table1.AddCell(new PdfPCell(new Paragraph("#1")));
table1.AddCell(new PdfPCell(new Paragraph("Tipo Fact: ")));
table1.AddCell(new PdfPCell(new Paragraph("Contado")));
table1.AddCell(new PdfPCell(new Paragraph("Fecha: ")));
table1.AddCell(new PdfPCell(new Paragraph("3/17/2017")));
table1.AddCell(new PdfPCell(new Paragraph("Cedula: ")));
table1.AddCell(new PdfPCell(new Paragraph("207080801")));
table1.AddCell(new PdfPCell(new Paragraph("Cliente: ")));
table1.AddCell(new PdfPCell(new Paragraph("Errol")));

//add space here           
PdfPTable table2 = new PdfPTable(3);
table2.HorizontalAlignment = 1;
table2.WidthPercentage = 70;
table2.AddCell(new PdfPCell(new Paragraph("Producto", boldFont)));
table2.AddCell(new PdfPCell(new Paragraph("Cantidad", boldFont)));
table2.AddCell(new PdfPCell(new Paragraph("Subtotal", boldFont)));
table2.AddCell(new PdfPCell(new Paragraph("PDN130")));
table2.AddCell(new PdfPCell(new Paragraph("2")));
table2.AddCell(new PdfPCell(new Paragraph("18000")));
like image 786
Errol Chaves Moya Avatar asked Mar 17 '17 23:03

Errol Chaves Moya


1 Answers

You can use SpacingBefore or SpacingAfter on the tables. Both take a float parameter.

Example :

table1.SpacingBefore = 10f;
table1.SpacingAfter = 12.5f;
table2.SpacingBefore = 10f;
table2.SpacingAfter = 12.5f;
like image 171
Stanley S Avatar answered Nov 12 '22 16:11

Stanley S