itextsharp不能打印全部HTML

时间:2018-10-07 23:48:34

标签: asp.net itext

我正在尝试获取整个html表以显示我仅获得标题,而没有其他内容。如何迭代并获得所有桌子?

您将看到打印的附件,请原谅样式。一旦有效运行,我会处理。应该有更多,但正如我所说的,它仅显示第一行。

谢谢!

    <table id="Baseline_section_table" cellspacing="0" runat="server" style="width:100%;border-collapse:collapse;">
            <tr class="tableheader">
                <th style="border-width:0px;">Visit Name</th>
    <th style="border-width:0px;">Visit Date</th>
    <th style="border-width:0px;">Did the Subject have meas</th>
    <th style="border-width:0px;">Is the subject evaluable </th>
    <th style="border-width:0px;">Vote Status</th>
    <th style="border-width:0px;">Review Status</th>
            </tr>
    <tr class="tableSecondRow">
                <td>Baseline</td>
                <td>01-JUN-2018</td>
                <td>Yes</td>
                <td>Yes</td>
                <td>Closed</td>
            </tr>
        </table>Visit<table id="Visit_section_table" cellspacing="0" runat="server" style="width:100%;border-collapse:collapse;">
            <tr class="tableheader">
                <th style="border-width:0px;">Visit Name</th><th style="border-width:0px;">Visit Date</th><th style="border-width:0px;">Visit Response</th><th style="border-width:0px;">Reason(s) for PD</th><th style="border-width:0px;">Response Date</th><th style="border-width:0px;">Vote Status</th><th style="border-width:0px;">Review Status</th>
            </tr><tr class="tableSecondRow">
                <td>Visit 1</td><td>01-JUN-2018</td><td>Stringent Complete Response</td><td>Serum M-protein increase (sPEP), <br/> Urine M-protein increase (uPEP), <br/> Bone Marrow Plasma Cell percentage increase, <br/> Plasmacytomas (new or increase in size)</td><td>01-JUN-2018</td><td>Closed</td>
            </tr><tr class="tableSecondRow">
                <td>Visit 2</td><td>02-JUN-201</td><td>Stringent Complete Response</td><td>Urine M-protein increase (uPEP)</td><td>04-JUN-2018</td><td>Closed</td>
            </tr>
        </table>MRD<table id="MRD_section_table" cellspacing="0" runat="server" style="width:100%;border-collapse:collapse;">
            <tr class="tableheader">
                <th style="border-width:0px;">Visit Name</th><th style="border-width:0px;">Visit Date</th><th style="border-width:0px;">IMWG MRD</th><th style="border-width:0px;">Response Date</th><th style="border-width:0px;">Vote Status</th><th style="border-width:0px;">Review Status</th>
            </tr><tr class="tableSecondRow">
                <td>Visit 1 MRD</td><td>01-JUN-2018</td><td></td><td></td><td>Closed</td>
            </tr>
        </table>


Portion of my Code
  string hhh = HiddenFieldHtmlVal.Value;
            var sb = new StringBuilder();
            DivPrint.RenderControl(new HtmlTextWriter(new StringWriter(sb)));

            string imgUrl = Server.MapPath("~/").Replace("\\", "/");
            String htmlText = sb.ToString().Replace("../", imgUrl);

        StyleSheet styles = new StyleSheet();
            styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.FONTSIZE, "20PT");
            //styles.LoadTagStyle(HtmlTags.P, HtmlTags.FONTSIZE, "100");
            styles.LoadTagStyle(HtmlTags.P, HtmlTags.COLOR, "#ff0000");
            styles.LoadTagStyle(HtmlTags.UL, HtmlTags.BORDER, "1");
            styles.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BORDER, "0");

            // styles.LoadTagStyle(HtmlTags.TD, HtmlTags.f, "9");
            styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.BORDER, "1");


        //make an arraylist ....with STRINGREADER since its no IO reading file...
        // List<iTextSharp.text.IElement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(sb.ToString()), null);
        List<iTextSharp.text.IElement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);

        // ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);

        // Rectangle rect = PageSize.LETTER;



                var table = (PdfPTable)htmlarraylist[2];
                //var table = (PdfPTable)htmlElement;

                //if (table.NumberOfColumns == 2)
                table.WidthPercentage = 90;

                table.HorizontalAlignment = 0;
                table.SpacingBefore = 0f;
                table.SpacingAfter = 0f;


                FormatTable(table);



                document.Add(table);

enter image description here

0 个答案:

没有答案