1
votes

I new in using ITextSharp and want create a simple pdf file. And I trying in localhost, it work fine but put in server it fail to create and show the error message " The document has no pages.". I got try find the solution in web but still the same. How to solve this kind of problem?

Below is my coding.

 var html = GenerateHTML(lst, getuser);

                        Response.ContentType = "application/pdf";

                        Response.AddHeader("content-disposition", "attachment;filename=Commision_" + name + "_" + DateTime.Now.ToString("yyyyMM") + ".pdf");

                        Response.Cache.SetCacheability(HttpCacheability.NoCache);

                        //Render PlaceHolder to temporary stream

                        StringReader reader = new StringReader(html);

                        //Create PDF document

                        Document doc = new Document(PageSize.A4);

                        HTMLWorker parser = new HTMLWorker(doc);

                        PdfWriter.GetInstance(doc, Response.OutputStream);

                        doc.Open();
                        try
                        {
                            doc.NewPage();
                            parser.Parse(reader);
                        }
                        catch (Exception )
                        {
                        }
                        finally
                        {
                            doc.Close();
                        }
1
I'd also get rid of that catch clause. You may be hiding an error.David Crowell

1 Answers

-1
votes

I guess you missed the following 2 lines after doc.close

Response.Write(doc);
Response.End();