XMLWorkerHelper输出到PDFCell

时间:2013-04-17 13:15:03

标签: itextsharp

我正在尝试将XMLWorkerHelper的HTML输出设置为PdfPCell而不是Document。我做错了什么?

string html = "<h1>Test h1 Heading</h1><ul><li>html 1</li><li>html 2</li><li>html 3</li></ul>";

XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, new StringReader(html));

PdfPCell P4Type1 = new PdfPCell();
P4Tabel.AddCell(P4Type1); 

2 个答案:

答案 0 :(得分:1)

而不是使用单个Chunk与父{1}}一起工作,而父{/ 1}}是应用大多数格式的地方。并非所有IElement都可以添加,因此您需要检查IElements布尔属性:

IsContent()

答案 1 :(得分:1)

此代码已经过测试,可以将html字符串输入PdfPCell以写入pdf文档

string htmlFolioNotice = " <P align=center ><B> Thank you for your stay with us.Please visit us again.</B></P> " + "<P align=justify>NOTICE TO GUESTS: This property is privately owned and the management reserves the right to refuse service to anyone. Management will not be responsible for accidents or injury to guests or for loss of money, jewelry or valuables of any kind. Management will not be responsible for any item left in the room.<BR>&nbsp;<BR>CHECKOUT TIME: 11:00 AM SELF REGISTRATION ONLY I AGREE that my liability for this bill is not waived and agree to be held personally liable in the event that the indicated person or company failed to pay for any part or full amount of these charges including any missing/damaged items, etc.. I agreee that if an attorney is retained to collect these charges, I will pay all reasonable attorney's fees and costs incurred. If payment is by credit card you are authorized to charge my account for all charges incurred, including any and all damages/missing items, etc.. I agree that the sole purpose of renting this room is for my own residency only. Damge to property,Disturbance to guest or employees or Law Enforcement comes to your room. Immediate check out with no refund</P>";`enter code here`
PdfPTable tblNotise = new PdfPTable(1) { WidthPercentage = 100, HorizontalAlignment = 1, SpacingBefore = 20f };
    int[] tblNotisewidth = { 100 };
    tblNotise.SetWidths(tblNotisewidth);

    PdfPCell contentCell = new PdfPCell();
    contentCell.Border = 0;
    var htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlFolioNotice), null);
    for (int k = 0; k < htmlarraylist.Count; k++)
    {
        var ele = (IElement)htmlarraylist[k];
        contentCell.AddElement(ele);
    }
    tblNotise.AddCell(contentCell);
    docPDF.Add(tblNotise);