当我尝试将二进制文件转换为PDF时,pdf已损坏。
byte[] stream = presenter.getItemTable();
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader ("Content-Disposition", "attachment; filename=PressRelease.pdf");
Response.BinaryWrite(stream);//Entities.EDRSearchResult.ByteStream);
Response.Flush();
Response.End();
然而,当我将相同的二进制文件转换为Excel时,它工作正常并且可以打开而没有任何错误。
byte[] stream = presenter.getItemTable();
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "application/vnd.openxmlformats - officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition","attachment;filename=DataTable.xls");
Response.BinaryWrite(stream);
Response.Flush();
Response.End();
请帮帮我。
答案 0 :(得分:0)
当您尝试将二进制文件转换为PDF时,请编写
Response.AddHeader ("Content-Disposition", "attachment; filename=PressRelease.pdf");
尝试
Response.AddHeader ("content-disposition", "attachment; filename=PressRelease.pdf");