I need to get the content inside each page of a crystal report viewer and export it to a pdf file so that each page becomes a separate pdf and need to zip them. Now i'm using DotNetZip dll for this.That's fine.
The issue is that i need to get contents of each page.Please Help..Below is few lines of code
Response.ContentType = "application/zip";
Response.AppendHeader("content-disposition", "attachment; filename=Reports.zip");
int i = 1;
int PageCount = report.FormatEngine.GetLastPageNumber(new
CrystalDecisions.Shared.ReportPageRequestContext());
if(PageCount >= 1){
using (ZipFile zip = new ZipFile())
{
for (i = 1; i <= PageCount; i++){
var re = report.ExportToStream(ExportFormatType.PortableDocFormat);
string Name = "Page" + i + ".pdf";
zip.AddEntry(Name, re);
}
zip.Save(Response.OutputStream);
}
}
Finally i found the answer!!..It may help someone in future.
Response.ContentType = "application/zip";
Response.AppendHeader("content-disposition", "attachment; filename=Reports.zip");
int PageCount = report.FormatEngine.GetLastPageNumber(new
CrystalDecisions.Shared.ReportPageRequestContext());
if (PageCount >= 1)
{
using (ZipFile zip = new ZipFile())
{
for (int i = 1; i <= PageCount; i++)
{
PdfRtfWordFormatOptions pdfRtfWordOpts = ExportOptions.CreatePdfRtfWordFormatOptions();
DiskFileDestinationOptions destinationOpts = ExportOptions.CreateDiskFileDestinationOptions();
ExportRequestContext req = new ExportRequestContext();
pdfRtfWordOpts.FirstPageNumber = i;
pdfRtfWordOpts.LastPageNumber = i;
pdfRtfWordOpts.UsePageRange = true;
ExportOptions CrExportOptions = report.ExportOptions;
{
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.FormatOptions = pdfRtfWordOpts;
req.ExportInfo = CrExportOptions;
}
Stream s = report.FormatEngine.ExportToStream(req);
string Name = "Page" + i + ".pdf";
zip.AddEntry(Name, s);
}
zip.Save(Response.OutputStream);
}
}