I'm using iTextSharp to generate some PDF files. I have two tables which have content, and I want to put some space between the two tables, say the equivalent of 1 line of text (using the same font as the tables around the space).
Below is the code I'm using to add the two tables. What I cannot figure out is how to place a vertical space between the two tables.
Table upperTable = new Table(1);
upperTable.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
upperTable.AddCell(new Phrase("some text", font3));
d.Add(upperTable);
Table lowerTable= new Table(1);
lowerTable.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
lowerTable.AddCell(new Phrase("some other text", font3));
d.Add(lowerTable);
Can someone tell me how I can add the vertical space between the two tables?
Thanks!
I found a solution that sort of works... add the new lines as part of either the preceding string, or the following string to the space that I want to create. For example:
Table upperTable = new Table(1);
upperTable.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
upperTable.AddCell(new Phrase("some text" + '\n', font3));
d.Add(upperTable);
Table lowerTable= new Table(1);
lowerTable.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
lowerTable.AddCell(new Phrase('\n' + "some other text", font3));
d.Add(lowerTable);
would cause 2 lines whose height is defined by font3
to be added between the "some text"
and "some other text"
Use PdfPTable instead. It has properties SpacingBefore
and SpacingAfter
For example:
PdfPTable upperTable = new PdfPTable(1);
upperTable.AddCell(new Phrase("some text", font3));
upperTable.SpacingAfter = 10f;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With