Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# itext shatp嵌套<;ul>&书信电报;李>;在PdfPcell中使用c无法正确打印#_C#_Asp.net Mvc_Nested_Itextsharp - Fatal编程技术网

C# itext shatp嵌套<;ul>&书信电报;李>;在PdfPcell中使用c无法正确打印#

C# itext shatp嵌套<;ul>&书信电报;李>;在PdfPcell中使用c无法正确打印#,c#,asp.net-mvc,nested,itextsharp,C#,Asp.net Mvc,Nested,Itextsharp,这里有html文本数据 <ul> <li><strong>sf f</strong></li> <li><strong>sd gmdslkg &nbsp;</strong> <ul> <li><strong><span style="color:#FF0000">dsg&nbsp;</span

这里有html文本数据

<ul>
    <li><strong>sf f</strong></li>
    <li><strong>sd gmdslkg &nbsp;</strong>
    <ul>
        <li><strong><span style="color:#FF0000">dsg&nbsp;</span></strong></li>
        <li><span style="color:#FF0000"><strong>ffg&nbsp;</strong></span></li>
        <li><span style="color:#800080"><strong>dfg g fdghdf</strong></span>
        <ul>
            <li><span style="color:#EE82EE"><strong>dsg &nbsp;g</strong></span></li>
            <li><span style="color:#EE82EE"><strong>fdgh d</strong></span></li>
            <li><span style="color:#EE82EE"><strong>ghdf rfh&nbsp;</strong></span>
            <ul>
                <li><span style="color:#FFD700"><strong>hdf</strong></span></li>
                <li><span style="color:#FFD700"><strong>fdg dfghh</strong></span></li>
                <li><span style="color:#FFD700"><strong>bh dfh</strong></span></li>
            </ul>
            </li>
            <li><span style="color:#A52A2A"><strong>dfgh dfh&nbsp;</strong></span></li>
            <li><span style="color:#A52A2A"><strong>dfg&nbsp;</strong></span></li>
        </ul>
        </li>
        <li><strong>dfg dfghd r re 5ygtr &nbsp;ger</strong></li>
    </ul>
    </li>
    <li><span style="color:#FF8C00"><strong>gds mgds</strong></span></li>
    <li><span style="color:#B22222"><strong>dsfg sdg</strong></span></li>
</ul>

<ol>
    <li><span style="color:#40E0D0"><strong>dslmg lmdsg</strong></span></li>
    <li><strong>dsg&nbsp;</strong></li>
    <li><strong>&nbsp;<span style="color:#FFA500">grews</span></strong></li>
    <li><span style="color:#EE82EE"><strong>dgds g&nbsp;</strong></span></li>
    <li><span style="color:#EE82EE"><strong>gsrd h</strong></span></li>
    <li><span style="color:#800080"><strong>&nbsp;eg dsg w r4ewty 43 dfgbreg</strong></span></li>
    <li><span style="color:#800080"><strong>&nbsp;t43 t43tgfdfsgre</strong></span></li>
</ol>
  • sf f
  • sd gmdslkg
    • dsg
    • ffg
    • dfg fdghdf
      • dsg
      • fdgh d
      • ghdf rfh
        • hdf
        • fdg dfghh
        • bh dfh
      • dfgh-dfh
      • dfg
    • dfg dfghd r re 5ygtr ger
  • gds mgds
  • dsfg sdg
  • DSMG lmdsg
  • dsg
  • grews
  • dgds g
  • gsrd h
  • 例如dsg w r4ewty 43 dfgbreg
  • t43 T43TGDFSGRE
  • 现在,当我尝试使用以下代码在itex sharp pdf中打印时:

     var doc = new iTextSharp.text.Document();
                doc.Open();
    
                iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet();
                ST.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
    
                var tmpCellNote = new PdfPCell(new Phrase("Subcontractor Notes: ", noteFont)) { Border = 0, HorizontalAlignment = Element.ALIGN_LEFT, Colspan = 5 };
                tmpCellNote.PaddingLeft = (10 * schedule.Level);
                var objects = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(Convert.ToString(schedule.Notes)), ST);
                for (int k = 0; k < objects.Count; ++k)
                {
                    tmpCellNote.AddElement((IElement)objects[k]);
                }
                table.AddCell(tmpCellNote);
    
                doc.Add(table);
    
    var doc=new iTextSharp.text.Document();
    doc.Open();
    iTextSharp.text.html.simpleparser.StyleSheet ST=new iTextSharp.text.html.simpleparser.StyleSheet();
    ST.LoadTagStyle(HtmlTags.BODY,HtmlTags.ENCODING,BaseFont.IDENTITY_H);
    var tmpCellNote=new PdfPCell(新短语(“分包商注释:”,noteFont)){Border=0,HorizontalAlignment=Element.ALIGN_LEFT,Colspan=5};
    tmpCellNote.PaddingLeft=(10*schedule.Level);
    var objects=iTextSharp.text.html.simpleparser.HTMLWorker.parsetList(新的StringReader(Convert.ToString(schedule.Notes)),ST);
    for(int k=0;k
    使用上述代码,它将按如下方式打印:

    • sf f
    • sd gmdslkg
    • dsg
    • ffg
    • dfg fdghdf
    • dsg
    • fdgh d
    • ghdf rfh
    • hdf
    • fdg dfghh
    • bh dfh
    • dfgh-dfh
    • dfg
    • dfg dfghd r re 5ygtr ger
    • gds mgds
    • dsfg sdg
  • DSMG lmdsg
  • dsg
  • grews
  • dgds g
  • gsrd h
  • 例如dsg w r4ewty 43 dfgbreg
  • t43 T43TGDFSGRE
  • 那么,对于嵌套的
    • 标记,如何使用c#和itextsharp PdfPTable和PdfPCell实现这一点呢

      请帮帮我


      谢谢。

      ITextSharp库不支持该功能

      老实说,我不喜欢它。从HTML保存PDF需要大量工作。我一直使用的是Nreco.PdfGenerator,可在此处找到:

      现在,它支持嵌入式CSS、内联CSS、按CSS分页、按CSS设置表行为,以及所有内容。最好的工具,你可以找到免费获得HTML->PDF转换

      从HTML生成pdf的示例代码:

      var generator = new NReco.PdfGenerator.HtmlToPdfConverter();
      var fileLines = System.IO.File.ReadAllText(@"C:\TEMP\test.html"); //you can always use ANY html string, not exactly file
      var pdfBytes = generator.GeneratePdf(fileLines); //returns PDF byte[]
      System.IO.File.WriteAllBytes(@"C:\TEMP\test.pdf", pdfBytes); //save to PDF
      

      使用您的示例,我得到了与HTML结果相同的PDF结果

      我想把这个问题标记为一个重复的问题,因为所问的问题没有得到这个答案中所解释的支持:不幸的是,这个答案没有被接受,也没有被投票,所以我不能以此作为结束这个问题的理由。我想人们只是不喜欢答案是“不”…你好,布鲁诺,但在这个演示网站上,当我创建嵌套的
      • 时,它会工作得很好,它会以Pdf格式打印,与web视图一样。谢谢。但是您使用的是
        HTMLWorker
        ,而不是XML Worker
        HTMLWorker
        在许多年前已经被放弃,取而代之的是XML Worker。另外,如果您看一下这个示例,您会发现如果您想要在单元格中显示列表,您需要一个最新版本的iText。可能您使用的是过时版本的iText。您好,我使用的是5.5.4.0版的itextsharp。但当我在我的解决方案中包含并在我的页面中提供参考时。但我无法访问Xml Worker。您能否为PdfPCell中嵌套的
        • 使用Xml worker提供一些演示/示例?ThanksXML Worker需要一个额外的DLL:您可以在此处下载: