Click here to Skip to main content
15,888,026 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,
I have one Microsoft chart. I want to export that chart into pdf on button click.
This is my code in button click.

C#
Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=ForwardLoadHistory.pdf");        
        Response.ContentType = "application/pdf";        
        Response.Charset = "";
        StringWriter stringWriter = new StringWriter();
        HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
        chtEstHoursRemaining.RenderControl(htmlWriter);
        Response.Output.Write(stringWriter.ToString());
        Response.Flush();
        Response.End();

File is downloading .It is rendering properly. When i open file in wordpad it is properly showing rendered text but when i try to open file it is giving following error.

HTML
" Adobe reader could not open file 'ForwardLoadHistory.pdf' because it is either not a supported file type or because the  file has been damaged(for example it was sent as an email attachment and wasn't corrcetly decoded)".

I try to do it with ITextSharp but is giving me following error while parsing.
Illegal characters in path

Please give some helpful solution.
Posted
Updated 5-Aug-12 21:54pm
v2

 
Share this answer
 
hi
try this one


Response.AppendHeader("content-disposition", "attachment; filename=ForwardLoadHistory.pdf");
Response.ContentType = "Application/pdf";
Response.WriteFile(Server.MapPath("ForwardLoadHistory.pdf"));//

Response.Flush();

Response.Close();
//System.Threading.Thread.Sleep(5000);
System.IO.File.Delete(Server.MapPath("ForwardLoadHistory.pdf"));
Response.End();
 
Share this answer
 
Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Vendors List.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            hw.Write("<center><h3>Vendors List</h3></center><br /><br /><br /><br />");
            grdVendorList.AllowPaging = false;
            grdVendorList.DataBind();
            grdVendorList.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900