iTextSharp正在生成带有响应的损坏PDF
我尝试了两种,但仍然没有工作
iTextSharp + FileStream =损坏的PDF文件
iTextSharp正在生成一个损坏的PDF
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
//abre o documento para poder editar
document.Open();
//Adiciona os campos de assinatura
document.Add(Assinatura());
//fecha o documento ao finalizar a edição
document.Close();
//Prepara o download
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "image/pdf";
//Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;
filename=ControleDePonto.pdf");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}
什么即时做错了?
使用PdfWriter将PDF写入MemoryStream。
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
//Adiciona os campos de assinatura
document.Add(Assinatura());
//fecha o documento ao finalizar a edição
document.Close();
//Prepara o download
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=ControleDePonto.pdf");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
链接地址: http://www.djcxy.com/p/8185.html
上一篇: iTextSharp is producing a corrupt PDF with Response
下一篇: Do you need Adobe PDF installed on server to work with iTextSharp?