简体   繁体   中英

ITextSharp Error - The document has no pages

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();
                        }

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM