【问题标题】:problems downloading signed pdf files c#下载签名的pdf文件c#的问题
【发布时间】:2015-05-15 12:14:36
【问题描述】:

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

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

谁能帮我解决这个问题?

【问题讨论】:

    标签: pdf c#-4.0 signed downloading-website-files


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回答,我将这一行更改为:HttpContext.Current.Response.AddHeader("Content-Length", newStream.Length.ToString()); 其他:HttpContext.Current.Response.AddHeader("Content-Length", newStream.ToArray().Length.ToString());,我也遇到了同样的问题。我可以检查newStream 是否包含所有字节。因为我在下载之前保存了文件,我可以完美地阅读它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    • 2019-11-26
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多