首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >到PDFCell的XMLWorkerHelper输出

到PDFCell的XMLWorkerHelper输出
EN

Stack Overflow用户
提问于 2013-04-17 21:15:03
回答 2查看 1.1K关注 0票数 0

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

代码语言:javascript
复制
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); 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-18 21:15:33

与其使用单个Chunk,不如使用父IElement,它是应用大部分格式的地方。并不是所有的IElements都可以添加,所以你需要检查IsContent()的boolean属性:

代码语言:javascript
复制
PdfPCell P4Type1 = new PdfPCell();
foreach (var element in mh.elements) {
    if (element.IsContent()) {
        P4Type1.AddElement(element);
    }
}
票数 1
EN

Stack Overflow用户

发布于 2016-12-20 18:06:25

这段代码是经过测试的吧,那就给出html字符串写入PdfPCell中的pdf文件

代码语言:javascript
复制
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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16061062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档