【发布时间】:2012-11-16 11:24:15
【问题描述】:
我有一个生成 PDF 发票的 C# 应用程序。在这张发票中是一个项目和价格表。这是使用PdfPTable 和PdfPCells 生成的。
我希望能够右对齐价格列,但我似乎无法做到 - 单元格中的文本总是左对齐。
这是我创建表格的代码:
PdfPTable table = new PdfPTable(2);
table.TotalWidth = invoice.PageSize.Width;
float[] widths = { invoice.PageSize.Width - 70f, 70f };
table.SetWidths(widths);
table.AddCell(new Phrase("Item Name", tableHeadFont));
table.AddCell(new Phrase("Price", tableHeadFont));
SqlCommand cmdItems = new SqlCommand("SELECT...", con);
using (SqlDataReader rdrItems = cmdItems.ExecuteReader())
{
while (rdrItems.Read())
{
table.AddCell(new Phrase(rdrItems["itemName"].ToString(), tableFont));
double price = Convert.ToDouble(rdrItems["price"]);
PdfPCell pcell = new PdfPCell();
pcell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
pcell.AddElement(new Phrase(price.ToString("0.00"), tableFont));
table.AddCell(pcell);
}
}
谁能帮忙?
【问题讨论】:
-
我遇到了同样的问题,但没有找到
Phrase对象的可行解决方案。我可以建议的最好的方法是您使用Paragraph而不是Phrase并设置段落本身的对齐方式。
标签: c# itextsharp