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 MohapatraPosted Jan 21, 2014, 1:42 AM
please change the image location to
create a folder Image in your project solution and put your logopng inside that folder
to:
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 MohapatraPosted Jan 21, 2014, 2:19 AM
try
Vignesh KumarPosted Jan 21, 2014, 2:07 AM
Biswa Pujarini MohapatraPosted Jan 21, 2014, 1:38 AM
I believe you do not have enough permission on that folder please add "everyone" and give read/write access to that folder and try