简体   繁体   English

在水晶报表中循环导出为PDF

[英]exporting to PDF in a loop in crystal reports

I am facing difficulties in generating more than 1 PDF's of Crystal report ie in a loop. 我在生成多个PDF水晶报表(即循环生成)时遇到困难。 Basically I am creating PDF's then zipping those files and generating HTTP Response.For the sake of demonstration of code i am running loop twice here is my code. 基本上我创建的是PDF文件,然后压缩这些文件并生成HTTP Response。为演示代码,我在这里运行了两次代码。

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/zip";
Response.AppendHeader("content-disposition", "attachment; filename=Report.zip");
using (ZipFile zip = new ZipFile())
{                    
        for (int i = 0; i < 2; i++)
        {
            var re = rpt.ExportToStream(ExportFormatType.PortableDocFormat);
            string Name="PDF"+i+".pdf";
            zip.AddEntry(Name, re);
        }
        zip.Save(Response.OutputStream);                          
}

Response.Clear();

It successfully generates the zip file but when i try to extract it i gives an error No archive found (The archive is either in unknown formate or damaged). 它成功生成了zip文件,但是当我尝试提取该zip文件时,我给出了一个错误, No archive found (The archive is either in unknown formate or damaged).格式No archive found (The archive is either in unknown formate or damaged). Any help would be appreciated. 任何帮助,将不胜感激。 Btw I followed this link Export Crystal Report to PDF in a Loop only works with first 顺便说一句,我点击了此链接,“ 将Crystal Report循环导出为PDF”仅适用于

Using of memorystreem if zip file not attached to local path. 如果zip文件未附加到本地路径,则使用memorystreem。

Response.ClearContent(); Response.ClearContent(); Response.ClearHeaders(); Response.ClearHeaders();
Response.ContentType = "application/zip"; Response.ContentType =“应用程序/邮政编码”;
Response.AppendHeader("content-disposition", "attachment; Response.AppendHeader(“ content-disposition”,“ attachment;
filename=Report.zip"); 文件名= Report.zip“);

using (var memoryStream = new MemoryStream()) { using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) 使用(var memoryStream = new MemoryStream()){使用(var archive = new ZipArchive(memoryStream,ZipArchiveMode.Create,true))
{ {
for (int i = 0; i < 2; i++) 对于(int i = 0; i <2; i ++)
{ {
var re = rpt.ExportToStream(ExportFormatType.PortableDocFormat); var re = rpt.ExportToStream(ExportFormatType.PortableDocFormat);
string Name="PDF"+i+".pdf"; 字符串名称=“ PDF” + i +“。pdf”;
zip.AddEntry(Name, re); zip.AddEntry(名称,重新);
zip.Save(memoryStream); zip.Save(MemoryStream的);
} } } }}}

memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.Seek(0,SeekOrigin.Begin); memoryStream.WriteTo(Response.OutputStream); memoryStream.WriteTo(Response.OutputStream);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM