Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 19, 2013 06:24 PM by cityblue
Feb 24, 2012 01:34 PM|LINK
i am getting error like.,
Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph' in c#.
string path = Server.MapPath("PDFs"); /* pdfWriter class is need for commit the document to disk*/
//string imgPath = Server.MapPath("Images");
Response.ContentType = "application/pdf";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridViewMembers.AllowPaging = false;
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, new FileStream(path + "/Doc1.pdf", FileMode.Open));
htmlparser.Parse(sr); // This is the error place
Feb 24, 2012 01:45 PM|LINK
Most likely this is an issue with your HTML that you are passing to it. I've seen some threads regarding this on other sites that point to non-standard widths, (ie: px, cm instead of a number or percentage). Do you have some HTML that you can show us that
is blowing this up? We can't tell without it because it's an error from within iTextSharp, which means that something that is being thrown at it is causing a problem and not your actual code to generate the PDF.
Feb 24, 2012 01:57 PM|LINK
Sorry., I can't get clear with ur post.
Can u explain 1 sec clearly pls.......
Feb 24, 2012 03:10 PM|LINK
Basically, the problem is not your code. It's the HTML that you are passing to iTextSharp. There is most likely something it doesn't lik in the HTML.
One of the common things I have found when looking online for a solution is iTextSharp expects only numbers or percentages for certain things. Example: To set a table cell width it expects <td width="100"> or <td width="15%">. It blows up with a similar
error when you have <td width="100px">.
So somewhere in the HTML it could be badly formed with a mismatched tag (a closing tag is not in missing or in the wrong spot) or has a value that iTextSharp cannot parse or is not designed to parse.
Feb 25, 2012 04:43 AM|LINK
I checked all tags in my page, there is no wrong syntax.
Feb 19, 2013 06:24 PM|LINK
I guess the 'GridViewMembers' is a actual web control on your page, why not just creating a gridview in fly, ex:
GridView gv = new GridView();
gv.AllowPaging = false;
gv.DataSource = (datasource)
the if you want to customize the style
hopes it helps