0

im trying to convert my web page to pdf, i saw this code:

Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    this.Page.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();

im not realy sure what every line here does but i used it on a new site and it worked, when im trying to use it on my project i get error, this is the line which gives the error: htmlparser.Parse(sr);

this is the error: could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\pic\1.jpg'

i the pic\1.jpg is in my project so i added it to that path (i dont know if thats what i need to do) but then it gave me another error: Font size too small: 0

am i approaching the problem right? what do i need to do to fix it?

  • This is iTextSharp. First, `HTMLWorker` has been deprecated for a very, very long time and doesn't support CSS. Please use `XMLWorker` instead. See http://stackoverflow.com/q/9611535/231316 and http://stackoverflow.com/a/15362705/231316 – Chris Haas Oct 15 '13 at 13:51
  • Possible duplicate of [Convert webpage to HTML to PDF?](http://stackoverflow.com/questions/13689255/convert-webpage-to-html-to-pdf) – Thomas Jan 11 '17 at 11:53

1 Answers1

0

You could try to use Flying Saucer :

https://code.google.com/p/flying-saucer/

realUser404
  • 2,111
  • 3
  • 20
  • 38
  • tnx for the comment but its a bit complicated for me to start learning this and i cant find a sample for my use. do you know ho to fix my problem or any other button sample? – user2205625 Oct 15 '13 at 13:50