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.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
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.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
ssjGanesh
Participant
1928 Points
1352 Posts
Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp...
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";
Response.AddHeader("content-disposition", "attachment;filename=Doc1.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridViewMembers.AllowPaging = false;
GridViewMembers.DataBind();
GridViewMembers.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
PdfWriter.GetInstance(pdfDoc, new FileStream(path + "/Doc1.pdf", FileMode.Open));
pdfDoc.Open();
htmlparser.Parse(sr); // This is the error place
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
Mark as answer,if it helped U!
markfitzme
Star
14379 Points
2225 Posts
Re: Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextS...
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.
ssjGanesh
Participant
1928 Points
1352 Posts
Re: Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextS...
Feb 24, 2012 01:57 PM|LINK
Sorry., I can't get clear with ur post.
Can u explain 1 sec clearly pls.......
Mark as answer,if it helped U!
markfitzme
Star
14379 Points
2225 Posts
Re: Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextS...
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.
ssjGanesh
Participant
1928 Points
1352 Posts
Re: Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextS...
Feb 25, 2012 04:43 AM|LINK
I checked all tags in my page, there is no wrong syntax.
Mark as answer,if it helped U!
cityblue
Member
2 Points
1 Post
Re: Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextS...
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)
gv.DataBind();
gv.RenderControl(hw);
the if you want to customize the style
gv.HeaderRow.Style.Add("width", "15%");
gv.HeaderRow.Style.Add("font-size", "10px");
hopes it helps