locked
Unable to cast object of type 'iTextSharp.text.html.simpleparser.IncTable' to type 'iTextSharp.text.Rectangle" RRS feed

  • Question

  • User869548786 posted

    Hi,

    I have a datalist and within that datalist I have populated two gridviews(nested), for generating reports.

    All three are designed inside a html table.

    I have to convert the above to pdf.

    I do as below

    Response.ContentType = "application/pdf";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            System.IO.StringWriter stringWrite = new StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            tbReport.RenderControl(htmlWrite);
    //tbReport is a table
            StringReader reader = new StringReader(textConvert(stringWrite.ToString()));
            Document doc = new Document(PageSize.A4);
            HTMLWorker parser = new HTMLWorker(doc);
            PdfWriter.GetInstance(doc, Response.OutputStream);
            doc.Open();
            parser.Parse(reader);
            doc.Close();
    


    I get the error at this line

     parser.Parse(reader);

    "Unable to cast object of type 'iTextSharp.text.html.simpleparser.IncTable' to type 'iTextSharp.text.Rectangle""


    Googled a lot but with no avail for one whole day.

    Any suggestions please.

    Regards
    cmrhema



    Monday, January 4, 2010 8:34 PM

All replies

  • User869548786 posted

    Hi,


    I traced out the above error, somewhere there was a <tr> tag left unclosed with its correspond </tr> tag.


    After solving that issue when I once again try to convert into pdf, I have observe that the pdf is getting generated but not properly.

    i.e. the Datalist2 and the gridview2 present inside the datalist 2 is not getting populated.

    Any idea why is it working so.





    I have the html code as below

      <table id="tblReport" runat="server">
                <asp:DataList ID="DataList1" runat="server">
                    <ItemTemplate>
                        <tr>
                            <td>
                                <asp:Label ID="lbl1" runat="server">  </asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:GridView ID="GridView1" runat="server">
                                    <Columns>
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <asp:Label ID="lbl1" runat="server">  </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:GridView ID="GridView2" runat="server">
                                    <Columns>
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <asp:Label ID="lbl1" runat="server">  </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:DataList ID="DataList2" runat="server">
                                    <ItemTemplate>
                                        <table id="tblvalues" runat="server">
                                            <tr>
                                                <td>
                                                    <asp:GridView ID="GridView2" runat="server">
                                                        <Columns>
                                                            <asp:TemplateField>
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lbl1" runat="server">  </asp:Label>
                                                                </ItemTemplate>
                                                                <FooterTemplate>
                                                                    <asp:Label ID="lbl1" runat="server">  </asp:Label>
                                                                </FooterTemplate>
                                                            </asp:TemplateField>
                                                        </Columns>
                                                    </asp:GridView>
                                                </td>
                                            </tr>
                                        </table>
                                    </ItemTemplate>
                                </asp:DataList>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:DataList>
            </table>





    Friday, January 8, 2010 11:00 AM
  • User260017278 posted

    You need to bind your controls again.

    Wednesday, April 13, 2011 5:55 AM