ItextSharp error: document has no pages

I use itextsharp to convert my asp.net page to pdf. when I click the button, I write the following code:

Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); //GridView1.AllowPaging = false; GridView1.DataBind(); GridView1.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(); 

but I get an error: "The document has no page" please help me get rid of this error and create a pdf file.

+4
source share
1 answer

To do this, you need to take two steps:

1) Checking ITextSharp DLL is the latest version

and

2) Take the link to the button instead of the button and DO NOT use the hyperlink, since it will give an error using the hyperlink button.

0
source

All Articles