C#学习教程:iTextSharp正在使用Response生成损坏的PDF分享


iTextSharp正在使用Response生成损坏的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。

上述就是C#学习教程:iTextSharp正在使用Response生成损坏的PDF分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—猴子技术宅(www.ssfiction.com)

 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(); 

本文来自网络收集,不代表猴子技术宅立场,如涉及侵权请点击右边联系管理员删除。

如若转载,请注明出处:https://www.ssfiction.com/ckf/960197.html

发表评论

邮箱地址不会被公开。 必填项已用*标注