0
private void GeneratePDF(string path, string fileName, bool download, string text)
    {    
        var document = new Document();    
        try
        {    
            if (download)
            {    
                PdfWriter.GetInstance(document, Response.OutputStream);    
            }    
            else
            {    
                PdfWriter.GetInstance(document, new FileStream(path + fileName, FileMode.Create));    
            }   

            // generates the grid first    
            StringBuilder strB = new StringBuilder();

            document.Open();

            if (text.Length.Equals(0)) // export the text
            {    
                gvTransaction.DataBind();    
                using (StringWriter sWriter = new StringWriter(strB))
                {    
                    using (HtmlTextWriter htWriter = new HtmlTextWriter(sWriter))
                    {    
                        gvTransaction.RenderControl(htWriter);    
                    }    
                }    
            }    
            else // export the grid
            {    
                strB.Append(text);    
            }

            // now read the Grid html one by one and add into the document object
            using (TextReader sReader = new StringReader(strB.ToString()))
            {    
                List<IElement> list = HTMLWorker.ParseToList(sReader, new StyleSheet());    
                foreach (IElement elm in list)
                {    
                    document.Add(elm);    
                }    
            }    
        }    
        catch (Exception ee)
        {    
            lblMessage.Text = ee.ToString();
        }    
        finally
        {    
            document.Close();    
        }    
    }

    public override void VerifyRenderingInServerForm(Control control)
    {    
    }    

    protected void GeneratePDFAndDownload(object sender, EventArgs e)
    {    
        string fileName = "pdfDocument" + DateTime.Now.Ticks + ".pdf";

        GeneratePDF("", fileName, true, "");

        Response.Clear();    
        Response.ContentType = "application/pdf";    
        Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
        Response.Flush();
        Response.End();    
    }

I got the following code but when i run, it says

the document has no pages

Can someone help me as soon as possible? :(

Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
  • 2
    Your question is very unclear.. What are you using to create pdfs? what have you tried? have you verified the html contents? – Sayse Aug 05 '14 at 08:26
  • im using itextsharp. i just clicked the button onClick="GeneratePDFAndDownload" and it showed me " the document has no pages. – user3909477 Aug 05 '14 at 08:50
  • Typing "itextsharp document has no pages" into google returns [this question](http://stackoverflow.com/questions/19278623/itextsharp-the-document-has-no-pages). – Sayse Aug 05 '14 at 08:53
  • i dont understand why they say my document has no pages. im drained!! – user3909477 Aug 05 '14 at 09:42
  • Debug in the finally block just before closing the document if there is some content in the document or not. This possibly occurs when nothing is written to the document. – Abhishek Singh Aug 05 '14 at 09:45
  • how to write something into the document? – user3909477 Aug 05 '14 at 10:30

0 Answers0