【问题标题】:Retaining Indentation of the list after adding to PdfCell添加到 PdfCell 后保留列表的缩进
【发布时间】:2013-08-27 12:29:01
【问题描述】:

我在 pdfcell 中添加列表。但是该列表的标识不正确。 它是这样来的:

• One 
• Two
• Three

但是如果直接添加到文档中,相同的列表,标识是正确的。如下所示:

• One 
   • Two
• Three

这里是代码:

list = new List(false, 14.4F);
list.ListSymbol = new Chunk("\u2022", FontFactory.GetFont(FontFactory.HELVETICA, 10,iTextSharp.text.Font.BOLD));
ListItem listItem;
listItem = new ListItem(lstrBullets.Trim(), FontFactory.GetFont(FontFactory.HELVETICA, 10, iTextSharp.text.Font.NORMAL));
list.IndentationLeft = lftBulletIndent;    
listItem.SetLeading(10.0F, 1.0F);
listItem.Alignment = Element.ALIGN_JUSTIFIED;
list.Add(listItem);
PdfCell cell = new PdfCell();
cell.AddElement(list);
pobjTable.AddCell(cell);

lftBulletIndent 给出列表的缩进值。请帮助我在这里缺少什么。如何在单元格内保留缩进?

【问题讨论】:

  • 我无法复制您的基于文档的版本。我不认为多次更改list.IndentationLeft 应该做任何事情。该属性不应该被 iText 读取,直到您将其添加到某个对象时调用 Process 方法。您可以发布一些显示该工作的代码吗?另外,除非是拼写错误,因为您说PdfCell 是否意味着您使用的是非常旧的、已弃用且不受支持的 4.1.6 版本?
  • @ChrisHaas:我使用的是旧版本的 iTextsharp(3.1.8.0)。
  • 你能升级到更新的版本吗?当前版本是 5.4.3,它可能会解决您的问题。 3.1.8.0 已经六七岁了,已经路过了支持窗口。
  • @ChrisHaas:我无法升级到较新的版本。相反,我找到了解决方法,它提供了所需的格式。

标签: c# winforms itextsharp


【解决方案1】:

这就是我解决这个问题的方法。我知道这不是一个合适的。但它对我有用。
我在父表的第一个单元格中添加一个可变宽度的表,即这里 pobjTable

PdfPTable DummyTable = new PdfPTable(2);
//Here the floatSpace value changes according to the lftBulletIndent values
float[] headerwidths = { 2f + floatSpace, 98f - floatSpace};
DummyTable.SetWidths(headerwidths);

Pcell = new PdfPCell();
Pcell.Border = Rectangle.NO_BORDER;
DummyTable.AddCell(Pcell);


Pcell = new PdfPCell();
Pcell.AddElement(list);
Pcell.Border = Rectangle.NO_BORDER;
DummyTable.AddCell(Pcell);

pobjTable.AddCell(DummyTable);//Inserting a new table here
pobjTable.AddCell("");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 2021-02-09
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多