我想在iTextShart 5.5.9的页脚中使用HTML。我花了几个小时找到例子,但注意到了作品。我使用IPdfPageEvent OnEndPage添加页脚。此示例有效但不是HTML:
public void OnEndPage(PdfWriter writer, Document document)
{
var phrase = new Phrase("Footer");
PdfContentByte cb = writer.DirectContent;
ColumnText ct = new ColumnText(cb);
ct.SetSimpleColumn(phrase, document.Left, document.GetBottom(50), document.Right, document.Bottom, 10, Element.ALIGN_CENTER);
ct.Go();
}
此示例应该能够处理HTML,工作(编译)但不显示页脚。我做错了什么?
public void OnEndPage(PdfWriter writer, Document document)
{
ColumnText ct = new ColumnText(writer.DirectContent);
XMLWorkerHelper.GetInstance().ParseXHtml(new ColumnTextElementHandler(ct), new StringReader("Footer"));
ct.SetSimpleColumn(document.Left, document.Top, document.Right, document.GetTop(-20), 10, Element.ALIGN_MIDDLE);
ct.Go();
}
private class ColumnTextElementHandler : IElementHandler
{
public ColumnTextElementHandler(ColumnText ct)
{
_ct = ct;
}
private readonly ColumnText _ct;
public void Add(IWritable w)
{
if (w is WritableElement)
{
foreach (IElement e in ((WritableElement)w).Elements())
{
_ct.AddElement(e);
}
}
}
}