1

In the following code, Parse cannot take StringReader (sr) as input. How can I pass the string I have to Parse, then?

protected void LinkButton1_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);          

    string str = "<h1 title=’Header’ align=’Center’> Writing To PDF Using ASP.NET> <br><table align=’Center’><tr><td style=’width:100px;color:green’> <b>iTextSharp</b></td><td style=’width:100px;color:red’>mytestpdf</td></tr></table>";
    StringReader sr = new StringReader(str);
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);//Parse cannot take input as string reader (sr) how to solve?
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
}
joce
  • 9,624
  • 19
  • 56
  • 74
user3560627
  • 59
  • 3
  • 6
  • 1
    And the question is? Oh, I see the question burried in the code. Please reformat the question to make it more readable. See [Ask] and [FAQ] page for more information. – Steve B Apr 22 '14 at 13:37
  • http://msdn.microsoft.com/en-us/library/system.io.stringreader.readtoend.aspx – Dave Apr 22 '14 at 13:41
  • i am using itextsharp for convert to pdf.i get error in htmlparse.parse(sr). – user3560627 Apr 22 '14 at 13:46
  • 1Error 83 The best overloaded method match for 'iTextSharp.text.html.simpleparser.HTMLWorker.Parse(System.IO.StreamReader)' has some invalid arguments 2.Error 84 Argument 1: cannot convert from 'System.IO.StringReader' to 'System.IO.StreamReader' – user3560627 Apr 22 '14 at 13:51
  • What version of .net are you targeting and what version of iTextSharp are you using? – Chris Haas Apr 23 '14 at 01:01
  • yes it is problem of version.. – user3560627 Apr 23 '14 at 09:35

2 Answers2

0

Why are you putting your html into a StringReader? You already have the html in a string, just use that.

htmlparser.Parse(str)

If you must use StringReader for some reason, use the ReadToEnd() method to get a data type HTMLWorker.Parse will accept:

htmlparser.Parse(sr.ReadToEnd())
Dave
  • 4,375
  • 3
  • 24
  • 30
  • when i modify the code.. i got error cannot convert from 'string' to 'System.IO.StreamReader – user3560627 Apr 22 '14 at 14:31
  • Consult this question for information on how to convert a string to a StreamReader: http://stackoverflow.com/questions/1879395/how-to-generate-a-stream-from-a-string – Dave Apr 22 '14 at 14:40
0

I update the itextsharp 5.0.. .. now it not showing errors..

Stephan
  • 4,187
  • 1
  • 21
  • 33
user3560627
  • 59
  • 3
  • 6