I am creating a text file through code. which contains html tags like div h1 p etc. It also contains images with absolute path. I am creating pdf from this file on a button click. Pdf generation works fine except images doesn't appear on the pdf. I refered your blog
http://www.aspsnippets.com/Articles/Export-ASPNet-Web-Page-with-images-to-PDF-using-ITextsharp.aspx
and appended my text cintent to a div which displayed correctly, and using that div i tried to create the pdf. only change i made was replaced page.rendercontrol with my divid.rendercontrol. but this didn't help either. can you please help me out on this.
Below is my text file content
<p><img alt="" src="http://localhost:11589/NewsLetterImages/2.jpg" style="height:363px; width:545px" /></p>
<p> </p>
<p>Two-time World Championship bronze-medallist Sindhu advanced to the last eight of women's singles by notching up a dominating 21-13 21-15 win in 40 minutes over Chinese Taipei's Tai Tzu Ying yesterday which should serve as a good morale boost against the formidable Yihan.</p>
<p>Two-time World Championship bronze-medallist Sindhu advanced to the last eight of women's singles by notching up a dominating 21-13 21-15 win in 40 minutes over Chinese Taipei's Tai Tzu Ying yesterday which should serve as a good morale boost against the formidable Yihan.</p>
<p>Two-time World Championship bronze-medallist Sindhu advanced to the last eight of women's singles by notching up a dominating 21-13 21-15 win in 40 minutes over Chinese Taipei's Tai Tzu Ying yesterday which should serve as a good morale boost against the formidable Yihan.</p>
<p>Two-time World Championship bronze-medallist Sindhu advanced to the last eight of women's singles by notching up a dominating 21-13 21-15 win in 40 minutes over Chinese Taipei's Tai Tzu Ying yesterday which should serve as a good morale boost against the formidable Yihan.</p>
<p><img alt="" src="http://localhost:11589/NewsLetterImages/6.jpg" style="height:304px; width:456px" /></p>
<p> </p>
<p>Two-time World Championship bronze-medallist Sindhu advanced to the last eight of women's singles by notching up a dominating 21-13 21-15 win in 40 minutes over Chinese Taipei's Tai Tzu Ying yesterday which should serve as a good morale boost against the formidable Yihan.</p>
<p>Two-time World Championship bronze-medallist Sindhu advanced to the last eight of women's singles by notching up a dominating 21-13 21-15 win in 40 minutes over Chinese Taipei's Tai Tzu Ying yesterday which should serve as a good morale boost against the formidable Yihan.</p>
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(ConfigurationSettings.AppSettings["AdminNewsLetters"] + filename + ".txt");
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr1 = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr1.ReadToEnd();
sr1.Close();
myResponse.Close();
//newslettercontent is my div id
newsLetterContent.InnerHtml = result;
pnlView.Visible = true;
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);
newsLetterContent.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);
LoadGridData();
Response.End();
Thanks
Praveen