在IIS中托管时,iTextsharp pdf无法打开

时间:2012-11-06 08:33:00

标签: itextsharp

我正在使用iTextSharp为ASP.Net(c#)中的报表创建PDF。 Pdf成功创建&可以在运行应用程序时打开,但是当IIS中的iam托管时,它无法以PDF格式打开并出现错误:

“adobe reader无法打开pdf,因为它不是受支持的文件类型,或者因为文件已损坏”

我的代码如下:

Document pdfDoc = new Document();
pdfDoc.SetPageSize(PageSize.A4.Rotate());

string filepath = "Demo" + ".pdf";

string attachment = "attachment; filename=" + filepath;
Response.Charset = String.Empty;
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/PDF";

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();

//Adding some paragraph in to the pdfdoc.            

pdfDoc.Close();

Response.Write(pdfDoc);
Response.End();

我在等待你的伟大想法

1 个答案:

答案 0 :(得分:1)

我知道这是一篇旧帖子,但是我遇到了一个问题,我遇到的问题是关于ix用户的文件夹权限。

我刚刚右键单击了我的主文件夹,转到安全选项卡并选择.Net用户(对我而言是2)并完全控制。那是我的问题,并解决了。希望这可以帮助别人。