C# 用点填充PDFP表格单元格

C# 用点填充PDFP表格单元格,c#,itextsharp,C#,Itextsharp,我有一张PDFP表,我想把它布置成这样: Item1 ............ $10.00 Item1123123 ...... $50.00 Item3 ............ $75.00 这就是我到目前为止所做的: var tableFont = FontFactory.GetFont(FontFactory.HELVETICA, 7); var items = from p in ctx.quote_server_totals where p.item

我有一张PDFP表,我想把它布置成这样:

Item1 ............  $10.00
Item1123123 ......  $50.00
Item3 ............  $75.00
这就是我到目前为止所做的:

var tableFont = FontFactory.GetFont(FontFactory.HELVETICA, 7);
var items = from p in ctx.quote_server_totals
            where p.item_id == id
               && p.name != "total"
               && p.type != "totals"
            select p;

foreach (var innerItem in items)
{               
    detailsTable.AddCell(new Phrase(innerItem.type == "discount" ? "ADJUSTMENT -" + innerItem.name : innerItem.name, tableFont));
    detailsTable.AddCell(new Phrase(".......................................................", tableFont));
    detailsTable.AddCell(new Phrase(Convert.ToDecimal(innerItem.value).ToString("c"), tableFont));
}
document.Add(detailsTable);

如你所见,我唯一能让点延伸的方法就是手动输入它们;但是,这显然不起作用,因为每次运行此代码时,第一列的宽度都会不同。有什么办法可以做到这一点吗?谢谢。

如果您可以使用固定宽度的字体,如
FontFactory。COURIER
您的任务会简单得多

//Our main font
var tableFont = FontFactory.GetFont(FontFactory.COURIER, 20);

//Will hold the shortname from the database
string itemShortName;

//Will hold the long name which includes the periods
string itemNameFull;

//Maximum number of characters that will fit into the cell
int maxLineLength = 23;

//Our table
var t = new PdfPTable(new float[] { 75, 25 });

for (var i = 1; i < 10000; i+=100) {
    //Get our item name from "the database"
    itemShortName = "Item " + i.ToString();

    //Add dots based on the length
    itemNameFull = itemShortName + ' ' + new String('.', maxLineLength - itemShortName.Length + 1);

    //Add the two cells
    t.AddCell(new PdfPCell(new Phrase(itemNameFull, tableFont)) { Border = PdfPCell.NO_BORDER });
    t.AddCell(new PdfPCell(new Phrase(25.ToString("c"), tableFont)) { Border = PdfPCell.NO_BORDER });
}
//我们的主字体
var tableFont=FontFactory.GetFont(FontFactory.COURIER,20);
//将保存数据库中的短名称
字符串itemShortName;
//将保留包含句点的长名称
字符串itemNameFull;
//适合单元格的最大字符数
int maxLineLength=23;
//我们的桌子
var t=新的PdfPTable(新的浮点[]{75,25});
对于(变量i=1;i<10000;i+=100){
//从“数据库”获取我们的项目名称
itemShortName=“Item”+i.ToString();
//根据长度添加点
itemNameFull=itemShortName+''+新字符串('.',maxLineLength-itemShortName.Length+1);
//将两个单元格相加
t、 AddCell(新的PdfPCell(新短语(itemNameFull,tableFont)){Border=PdfPCell.NO_Border});
t、 AddCell(新的PdfPCell(新短语(25.ToString(“c”),tableFont)){Border=PdfPCell.NO_Border});
}

请下载并搜索
DottedLineSeparator
。此分隔符类将在
段落的两部分之间画一条虚线(如本书中的图所示)。您可以找到Java图书样本的C版本。

选择总宽度(项目名称+xx.xx美元+填充)。减去项目名称、填充和总计。打印出那么多点。啊;先生,您是一位绅士和学者。。。我向你致敬。愿你的日子充满温暖和无尽的恩赐!