【发布时间】:2014-07-18 00:29:53
【问题描述】:
我是使用 ITextSharp 的新手,想创建一个简单的 pdf 文件。我在 localhost 中尝试,它工作正常,但放入服务器它无法创建并显示错误消息“文档没有页面。”。我试着在网上找到解决方案,但还是一样。如何解决此类问题?
下面是我的代码。
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();
}
【问题讨论】:
-
我也会去掉那个
catch子句。您可能隐藏了一个错误。
标签: c# asp.net itextsharp