我是iTextSharp的新手。在下面的代碼設置PdfPCell VerticalAlignment(我認爲在文本模式)不做任何事情,文本仍然對齊到單元格的底部。 根據多個在線示例,它應該工作,但沒有。設置HorizontalAlignment的作品。 請幫忙。謝謝iTextSharp PdfPCell.VerticalAlignment在文本模式下不起作用
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版本? –