Reputation: 12430
I have a very simple itextsharp table like this:
PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1;
table.AddCell(cell);
table.AddCell("Col 1 Row 1");
table.AddCell("Col 2 Row 1");
table.AddCell("Col 3 Row 1");
// Create spacing after row here only.
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");
doc.Add(table);
How can I create a space between row 1 and row 2 only?
Thanks.
Upvotes: 3
Views: 18537
Reputation: 467
Use the below code to add new line
PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1;
table.AddCell(cell);
table.AddCell("Col 1 Row 1");
table.AddCell("Col 2 Row 1");
table.AddCell("Col 3 Row 1");
//For blank line
PdfPCell blankCell = new PdfPCell(new Phrase(Chunk.NEWLINE));
blankCell.Border = PdfPCell.NO_BORDER;
table.AddCell(blankCell);
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");
doc.Add(table);
Upvotes: 0
Reputation: 1146
table.Add(new Phrase("\n", new iTextSharp.text.Font(
iTextSharp.text.Font.FontFamily.HELVETICA,
4f,
FONT.NORMAL)));
You can add this 'new line' to your document too: 'document.Add(new Phrase("\n"..., where the 'document' is an iTextSharp Document instance.
Upvotes: 0
Reputation: 6056
if you want to add blank row as i understand please: Try this:
PdfPTable table = new PdfPTable(3);
PdfPCell 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");
PdfPCell cellBlankRow = new PdfPCell(new Phrase(" "));
cell.Colspan = 3;
cell.HorizontalAlignment = 1;
table.AddCell(cellBlankRow);
table.AddCell("");
table.AddCell("");
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");
Just insert blank rows using Phrase
. I have tested and works fine..! If i am misunderstand please let me know..!
Upvotes: 8