0
我正在使用iTextSharp爲ASP.Net(c#)中的報表創建PDF。創建 全文成功&可以運行應用程序時可以打開,但是當IAM託管在IIS它可以在PDF無法打開,並給出錯誤:iTextsharp pdf在IIS中託管時無法打開
「的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();
我等着你的greatfull想法
什麼是「Response.Write(pdfDoc);」線路好嗎? PDF本身通過「PdfWriter.GetInstance(pdfDoc,Response.OutputStream)」的方式導出。因此,該Response.Write調用很可能會將垃圾添加到響應中。 – mkl
有沒有更好的方法來做到這一點? – Adersh
爲什麼你想這樣做(即返回PDF以外的東西)呢?如果你不想,只需刪除「Response.Write(pdfDoc);」線。 – mkl