Hi,
I am trying to export webpage to pdf and I get the below error. Not sure what is causing the error.
Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\Images\Logo.PNG'.
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void ExporttoPDF(object sender, EventArgs e)
{
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();
}
I get the error at the highlighted line.
Loading

Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 20, 2014, 8:42 PM EST
please change the image location to
create a folder Image in your project solution and put your logopng inside that folder
img src="C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\Images\Logo.PNG" />to:
img src=http://www.yourwebsite.com/Images/logo.png />Otherwise you can use
Server.MapPath("Images/logo.jpg")to get the full URL by code. However that implies you having to know the relative path to the image (meaning access to the raw html) at compile-time, which makes your code less maintainable.Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 20, 2014, 8:38 PM EST
I believe you do not have enough permission on that folder please add "everyone" and give read/write access to that folder and try
Vignesh KumarRank #1,578 · 1K reputationPosted Jan 20, 2014, 9:07 PM EST
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 20, 2014, 9:19 PM EST
try