2015-05-15 11 views
0

我有一个签名的pdf,Adobe签名很好。我想要下载此文档时,我的问题就开始了。下载已签名的pdf文件的问题c#

通过的webmethod我得到的签名文件的字节数。直到这里没有问题。

如果我尝试将文件保存在我的服务器上,当我打开该文件的一切是正确的。但是,如果我打开它时尝试下载,则签名是错误的。

这是Adobe Reader的错误:

“的署名数据的范围是由一系列意外的字节定义 详细情况:签名的字节范围无效”

这是我下载的文件的方式:

HttpContext.Current.Response.ContentType = "application/pdf"; 
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename= Factura.pdf"); 
HttpContext.Current.Response.AddHeader("Content-Length", newStream.Length.ToString()); 
HttpContext.Current.Response.Buffer = true; 
HttpContext.Current.Response.BufferOutput = true; 
HttpContext.Current.Response.Clear(); 
HttpContext.Current.Response.OutputStream.Write(newStream.GetBuffer(), 0, newStream.GetBuffer().Length); 
HttpContext.Current.Response.OutputStream.Flush(); 
HttpContext.Current.ApplicationInstance.CompleteRequest(); 

谁能帮我解决这个问题?

回答

1

您正在发送比标头中广告的更多字节。请执行newStream.ToArray()并只使用字节数组。其他的事情要检查的是,如果你真的有newStream所有的字节,保存到一个文件来检查(从ToArray()

+0

谢谢你的答案,我改变了这一行:'HttpContext.Current.Response.AddHeader(“ Content-Length“,newStream.ToArray()。Length.ToString());'和I(”Content-Length“,newStream.Length.ToString());'为这个其他的:'HttpContext.Current.Response.AddHeader有同样的问题 我可以检查'newStream'是否有所有字节,因为我在下载文件之前保存了文件,我可以完美地读取它 –