基本上,用户应该能够单击一个链接并下载多个 pdf 文件。但问题是我无法在服务器或任何地方创建文件。一切都必须在记忆中。
我能够将内存流和 Response.Flush() 创建为 pdf,但是如何在不创建文件的情况下压缩多个内存流。
这是我的代码:
Response.ContentType = "application/zip";
// If the browser is receiving a mangled zipfile, IIS Compression may cause this problem. Some members have found that
// Response.ContentType = "application/octet-stream" has solved this. May be specific to Internet Explorer.
Response.AppendHeader("content-disposition", "attachment; filename=\"Download.zip\"");
Response.CacheControl = "Private";
Response.Cache.SetExpires(DateTime.Now.AddMinutes(3)); // or put a timestamp in the filename in the content-disposition
byte[] abyBuffer = new byte[4096];
ZipOutputStream outStream = new ZipOutputStream(Response.OutputStream);
outStream.SetLevel(3);
#region Repeat for each Memory Stream
MemoryStream fStream = CreateClassroomRoster();// This returns a memory stream with pdf document
ZipEntry objZipEntry = new ZipEntry(ZipEntry.CleanName("ClassroomRoster.pdf"));
objZipEntry.DateTime = DateTime.Now;
objZipEntry.Size = fStream.Length;
outStream.PutNextEntry(objZipEntry);
int count = fStream.Read(abyBuffer, 0, abyBuffer.Length);
while (count > 0)
{
outStream.Write(abyBuffer, 0, count);
count = fStream.Read(abyBuffer, 0, abyBuffer.Length);
if (!Response.IsClientConnected)
break;
Response.Flush();
}
fStream.Close();
#endregion
outStream.Finish();
outStream.Close();
Response.Flush();
Response.End();
这会创建一个 zip 文件,但里面没有文件
我正在使用 iTextSharp.text - 使用 ICSharpCode.SharpZipLib.Zip 创建 pdf - 用于压缩
谢谢,卡维塔