Reputation: 4028
I am using code from other question and i am getting the error as
Error 1 The non-generic type 'iTextSharp.text.List' cannot be used with type arguments
Error 2 The name 'HTMLWorker' does not exist in the current context
Error 3 The type or namespace name 'HTMLWorker' could not be found (are you missing a using directive or an assembly reference?)
My code so far is as follows:
protected void Button2_Click(object sender, EventArgs e)
{
//Extract data from Page (pd).
Label16.Text = Editor1.Content; // Attribute
// makae ready HttpContext
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
// Create PDF document
Document pdfDocument = new Document(PageSize.A4, 80, 50, 30, 65);
//PdfWriter pw = PdfWriter.GetInstance(pdfDocument, HttpContext.Current.Response.OutputStream);
PdfWriter.GetInstance(pdfDocument, HttpContext.Current.Response.OutputStream);
pdfDocument.Open();
//WebClient wc = new WebClient();
string htmlText = Editor1.Content;
List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), null);
for (int k = 0; k < htmlarraylist.Count; k++)
{
pdfDocument.Add((IElement)htmlarraylist[k]);
}
//pdfDocument.Add(new Paragraph(IElement));
pdfDocument.Close();
HttpContext.Current.Response.End();
}
Please Help me to resolve the error. What i am trying is to get the contents (non html) from htmleditor and display in a pdf file. please confirm me whether what i am trying to do is correct or not.
Upvotes: 1
Views: 14746
Reputation: 11155
1.Prefix your List like
System.Collections.Generics.List<IElement> htmlarraylist
2.Looks like you didn't import the namespace of HTMLWorker
EDIT:I googled for you ,the namespace could be any of these three.I doubt it could be the last one,but i am not sure.
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
Upvotes: 3
Reputation: 9672
There's a name conflict in this code - you are using iTextSharp.text
namespace and trying to use standard System.Collections.Generic.List<T>
class.
Either you need to remove using iTextSharp.text
and use its classes with explicit namespace or use explicit namespace for List<T>
.
System.Collections.Generic.List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), null);
The third solution is to use aliases.
And for the second error, you need to import HTMLWorker
namespace. Put
using iTextSharp.text.html.simpleparser;
at the top.
Upvotes: 3