简体   繁体   English

ITextSharp错误-文档无页面

[英]ITextSharp Error - The document has no pages

I new in using ITextSharp and want create a simple pdf file. 我是ITextSharp的新手,并希望创建一个简单的pdf文件。 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.". 而且我在localhost中尝试正常,但在服务器中创建失败,并显示错误消息“文档无页面。”。 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 我想您在doc.close之后错过了以下两行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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