如何在pdfpcell上强制对齐对齐

时间:2013-05-07 20:02:32

标签: asp.net html itextsharp

证明pdfpcell上的文字是正确的,我知道这些命令

PdfPCell Example= new PdfPCell(new paragraph("Some text here",MyFont));//previous created font
Example.HorizontalAlignment = Element.ALIGN_JUSTIFIED;

但我有一个hmtl字符串,我需要解码,我这样做

string txt = "long html string text"
PdfPCell Example2= new PdfPCell();
List<IElement> sr = HTMLWorker.ParseToList(new StringReader(txt ), style);//style was previous created
foreach (IElement element in sr)
{
    Example2.AddElement(element);
}
Example2.SetLeading(0f, 1.5f);
Example2.Border = 0;
Example2.PaddingBottom = 20;
Table1.AddCell(Example2);//table declared previous

好的,直到这一点全部正常,我的pdfp文档很好,但我需要忽略html字符串的对齐并强制所有文本都是合理的。

我试过这个

Example2.HorizontalAlignment = Element.ALIGN_JUSTIFIED;

但不起作用。

1 个答案:

答案 0 :(得分:1)

在第一个示例中,您正在使用“文本模式”,并且尊重单元格的属性。

一旦你使用AddElement(),你就会以“复合模式”工作,并且忽略单元格的属性(如我的书中所述)。相反,使用单独元素的属性。

回答你的问题:你不应该在单元格的层面定义对齐,而是在元素层面定义。

相关问题