Click here to Skip to main content
15,885,981 members
Please Sign up or sign in to vote.
3.20/5 (3 votes)
See more:
Here i am creating pdf this is my code
C#
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=SanghiOrder.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GetAddTocartData2();
GridView1.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, new FileStream(Server.MapPath("~/pdf/Order" + OrderNumber + ".pdf"), FileMode.Create));
pdfDoc.Open();
htmlparser.Parse(sr);  //Here Error is Getting
pdfDoc.Close();
Response.End();

while creating pdf am getting errror like this

Here am getting server 404 error ...Please Help me
Posted
v3
Comments
While debugging, please check the value of sr on the line htmlparser.Parse(sr);.
Sergey Alexandrovich Kryukov 1-Nov-13 9:32am    
From the first glance: I don't see where you actually write any data to HTTP response, except the headers...
—SA

1 solution

As an alternative you may use iTextSharp for create PDF.

C#
using iTextSharp.text;
using iTextSharp.text.pdf;

var doc1 = new Document();

//use a variable to let my code fit across the page...
string path = Server.MapPath("PDFs");
PdfWriter.GetInstance(doc1, new FileStream(path + "/Doc1.pdf", FileMode.Create));

doc1.Open();
doc1.Add(new Paragraph("My first PDF"));
doc1.Close();


For more info check this : Create PDFs in ASP.NET

I hope this will help to you.
 
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