【发布时间】:2014-02-26 17:28:15
【问题描述】:
我是 iTextSharp 的新手。在下面的代码设置 PdfPCell 的 VerticalAlignment (我认为在文本模式下)没有做任何事情,文本仍然与单元格底部对齐。 根据多个在线示例,它应该可以工作,但不能。设置 HorizontalAlignment 有效。 请帮忙。谢谢
table = new PdfPTable(5);
Document document = new Document(PageSize.A4);
document.Open();
PdfPTable headerTable = new PdfPTable(3);
float[] headerWidths = { 2f, 5f, 2f };
headerTable.SetWidths(headerWidths);
myFont = FontFactory.GetFont("Arial", 8, Font.NORMAL);
PdfPCell myCell = setupHeaderCell("My Text", myFont);
// ADD headerTable to MainTable
// Creates a PdfPCell that accepts the headerTable as a parameter and then adds that cell to the main PdfPTable.
PdfPCell cellHeader = new PdfPCell(headerTable);
cellHeader.Border = PdfPCell.NO_BORDER;
// Sets the column span of the header cell to dataColumNb.
cellHeader.Colspan = 5;
// Adds the above header cell to the table.
table.AddCell(cellHeader);
................
}
private PdfPCell setupHeaderCell(string lineText, Font myFont)
{
var cl = new PdfPCell(new Phrase(lineText, myFont);
cl.VerticalAlignment = Element.ALIGN_MIDDLE; // does Not change vertical alignment
return cl;
}
【问题讨论】:
-
您使用的是哪个 iText 版本?
标签: itextsharp itext