PDF文件从网站下载后无法在adobe中打开,但可以在Edge中打开
PDF file cannot be opened in adobe upon download from website but can be opened in Edge
我有一个网络应用程序 运行 aspx,它有点像旧版应用程序。在提交过程中,用户将支持文件(通常是转换为 pdf 的图片)上传到我们的 sql 服务器,在那里它们以二进制文件的形式存储,并且可以在批准期间的不同时间再次下载。
但是,我们现在刚刚开始遇到一个问题,即我们的用户无法在 adobe 中打开 pdf,并收到可怕的 "The file is damaged and could not be repaired." 错误消息。它们仍然可以在 MS Edge 中打开,因此它们实际上并没有损坏。我已经确认 pdf 可以在上传之前正常打开。
HttpPostedFile file = this.attachmentUploader.PostedFile;
if (file == null)
{
file = Session["postedFile"] as HttpPostedFile;
}
if (file != null)
{
var fileName = this.attachmentUploader.FileName;
fileName = fileName.Length >= 100 ? string.Concat(fileName.Substring(0, 50).Trim(), ".pdf") : fileName;
Attachment attachment = new Attachment()
{
FileName = fileName,
File = this.attachmentUploader.FileBytes
};
db.Attachments.Add(attachment);
db.SaveChanges();
}
这是下载码
byte[] file = null;
// Code here to pull file from db
if (file != null)
{
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=support_doc.pdf");
Response.OutputStream.Write(file, 0, file.Length);
}
感谢任何帮助!
下载的文件实际上由两个串联文件组成,实际 PDF 和 HTML 文件。
HTML 文件大小将近 70 KB,在没有外部 JavaScript 和图像的情况下,它看起来像这样:
[--- 出于隐私原因删除了图片 ---]
我假设在您的 "download code" 之后,一些其他代码将此 HTML 添加到输出中。
您可能想要搜索该代码,或者您可能只想关闭 Response.OutputStream
并在 Response.OutputStream.Write(file, 0, file.Length)
之后立即完成响应。
根据 PDF 规范,PDF 处理器必须从有交叉引用信息的末尾开始读取 PDF,但就手头的文件而言,就 PDF 语法而言,有将近 70 KB 的垃圾关注。
因此,任何 PDF 查看器都可以拒绝该文件作为无效文件。
我有一个网络应用程序 运行 aspx,它有点像旧版应用程序。在提交过程中,用户将支持文件(通常是转换为 pdf 的图片)上传到我们的 sql 服务器,在那里它们以二进制文件的形式存储,并且可以在批准期间的不同时间再次下载。
但是,我们现在刚刚开始遇到一个问题,即我们的用户无法在 adobe 中打开 pdf,并收到可怕的 "The file is damaged and could not be repaired." 错误消息。它们仍然可以在 MS Edge 中打开,因此它们实际上并没有损坏。我已经确认 pdf 可以在上传之前正常打开。
HttpPostedFile file = this.attachmentUploader.PostedFile;
if (file == null)
{
file = Session["postedFile"] as HttpPostedFile;
}
if (file != null)
{
var fileName = this.attachmentUploader.FileName;
fileName = fileName.Length >= 100 ? string.Concat(fileName.Substring(0, 50).Trim(), ".pdf") : fileName;
Attachment attachment = new Attachment()
{
FileName = fileName,
File = this.attachmentUploader.FileBytes
};
db.Attachments.Add(attachment);
db.SaveChanges();
}
这是下载码
byte[] file = null;
// Code here to pull file from db
if (file != null)
{
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=support_doc.pdf");
Response.OutputStream.Write(file, 0, file.Length);
}
感谢任何帮助!
下载的文件实际上由两个串联文件组成,实际 PDF 和 HTML 文件。
HTML 文件大小将近 70 KB,在没有外部 JavaScript 和图像的情况下,它看起来像这样:
[--- 出于隐私原因删除了图片 ---]
我假设在您的 "download code" 之后,一些其他代码将此 HTML 添加到输出中。
您可能想要搜索该代码,或者您可能只想关闭 Response.OutputStream
并在 Response.OutputStream.Write(file, 0, file.Length)
之后立即完成响应。
根据 PDF 规范,PDF 处理器必须从有交叉引用信息的末尾开始读取 PDF,但就手头的文件而言,就 PDF 语法而言,有将近 70 KB 的垃圾关注。
因此,任何 PDF 查看器都可以拒绝该文件作为无效文件。