Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can add space\margin between two elements in iTextSharp\iText?

Tags:

I am pretty new in iTextSharpt (the iText porting for C#) and I have the following doubt.

In my code I have something like it:

iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph(currentVuln.Title, _fontTitolo0); titolo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; _document.Add(titolo);  table = new PdfPTable(3); table.WidthPercentage = 98;  cell = new PdfPCell(new Phrase("Header spanning 3 columns")); cell.Colspan = 3; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right table.AddCell(cell);  table.AddCell("Col 1 Row 1"); table.AddCell("Col 2 Row 1"); table.AddCell("Col 3 Row 1"); table.AddCell("Col 1 Row 2"); table.AddCell("Col 2 Row 2"); table.AddCell("Col 3 Row 2");  _document.Add(table); 

As you can see I simply print a title (usinga Paragraph object) and under it a place a table.

The problem is that there is no space (margin) between my title and my table and the graphic result is not good, this is what I obtain in the generated PDF:

enter image description here

What can I do to add some space\margin between the title paragraph and the table? What is the best way to do it? I am trying to do it but, untill now, I have found no solution

Tnx

like image 318
AndreaNobili Avatar asked Apr 07 '14 10:04

AndreaNobili


1 Answers

You have a couple of different options. You could set the SpacingAfter on your paragraph:

titolo.SpacingAfter = 20; 

You could also set the SpacingBefore on the table:

table.SpacingBefore = 20; 

Or you could just add some returns to your paragraph:

iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph("Hello World\n\n"); 
like image 64
Chris Haas Avatar answered Sep 20 '22 03:09

Chris Haas