下载签名的pdf文件时出现问题c#

problems downloading signed pdf files c#

我有一个带有 Adob​​e 签名的签名 pdf,做得很好。当我想下载这个文档时,我的问题就出现了。

通过网络方法,我得到了签名文件的字节数。直到这里没有问题。

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

这是 adobe reader 中的错误:

"The scope of the signed data is defined by a range of unexpected bytes. Details: The range of bytes of the signature is invalid"

这是我下载文件的方式:

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

谁能帮我解决这个问题?

您发送的字节数超过 header 中公布的字节数。做 newStream.ToArray() 并且只使用字节数组。另一件要检查的事情是,如果你真的拥有 newStream 中的所有字节,请将其保存到文件中进行检查(来自 ToArray().