【发布时间】:2012-03-29 03:30:42
【问题描述】:
ITextSharp 的表格有问题。我想要没有顶部和底部填充的单元格,以便它们彼此靠近。
虽然我已将单元格的填充和前导设置为 0,但空白仍然存在。
请问有人知道怎么去掉空格吗?
编辑:
感谢 Dylan 的及时回答,我已经设法解决了我的问题。如果有人遇到类似问题,这是源 sn-p
Document document = new Document(PageSize.A4, 5, 5, 10, 10);
using (FileStream fs = new FileStream("C:\\Users\\brum\\Desktop\\untitled.pdf", FileMode.Create))
{
iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
document.Open();
PdfPTable table = new PdfPTable(2);
PdfPCell cell = new PdfPCell(new Phrase("Spanning 2 cols"));
cell.Colspan = 2;
cell.HorizontalAlignment = 1;
cell.Padding = 0f;
cell.UseAscender = true;
table.AddCell(cell);
table.AddCell("Next row 1");
table.AddCell("Next row 2");
document.Add(table);
document.Close();
}
cell.UseAscender = true; // This is the line that did the trick for me
【问题讨论】:
-
天哪!... :D 每个单元格中的顶部空白区域让我发疯了。因此,垂直对齐无法正常工作。
-
供将来参考,这也在 iTextSharp 文档中说明,例如:afterlogic.com/mailbee-net/docs-itextsharp/html/…
标签: c# pdf itext cellpadding