iTextSharp error - cannot convert type 'Collections.Generic.List' to 'iTextSharp.text.Element'
Posted
by
mike
on Stack Overflow
See other posts from Stack Overflow
or by mike
Published on 2012-11-21T10:33:08Z
Indexed on
2012/11/21
11:00 UTC
Read the original article
Hit count: 891
I am trying to export pdf file using aspx and c#. I got the following error.
Cannot implicitly convert type 'System.Collections.Generic.List'' to 'iTextSharp.text.Element'
I have the following code
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
StringBuilder strB = new StringBuilder();
document.Open();
if (text.Length.Equals(0))//export the text
{
GridView1.DataBind();
using (StringWriter sWriter = new StringWriter(strB))
{
using (HtmlTextWriter htWriter = new HtmlTextWriter(sWriter))
{
GridView1.RenderControl(htWriter);
}
}
}
else //export the grid
{
strB.Append(text);
}
using (TextReader sReader = new StringReader(strB.ToString()))
{
StyleSheet styles = new StyleSheet();
List<Element> list = new List<Element>();
list = HTMLWorker.ParseToList(sReader, styles);
foreach (IElement elm in list)
{
document.Add(elm);
}
}
I got the error in this line: list = HTMLWorker.ParseToList(sReader, styles);
It's the first time that I am trying to export pdf files. I tried to cast the list element , however this did not solve my error.
Any advice would be helpful!!!
© Stack Overflow or respective owner