Hi Team,
I have requirement of splitting the PDF and download as single ZIP file.I am facing the issue like when i download the zip file the split pdf files are not available and the zip file is corrupt.Please help me as soon as possible.I fyou have better code snippet than this please send me this also.I have used .NET based zip class objects to create and add zip file and pdf file entries respectively.
parameter “inputPdfObject” is the input pdf file and it is a byte array object of the uploaded pdf.
MemoryStream memoryStream = new MemoryStream();
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(@"…\App_Data\Aspose.Pdf.lic");
if (Aspose.Pdf.Document.IsLicensed)
{
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(new MemoryStream(inputPdfObject));
var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true);
int pageCount = 1;
foreach (Page pdfPage in pdfDocument.Pages)
{
Aspose.Pdf.Document newDocument = new Aspose.Pdf.Document();
newDocument.Pages.Add(pdfPage);
ZipArchiveEntry zipFileEntry = archive.CreateEntry(“Split” + pageCount + “.pdf”);
using (Stream ZipFile = zipFileEntry.Open())
{
Stream splitStream = new MemoryStream();
newDocument.Save(splitStream, SaveFormat.Pdf);
byte[] splitPdf = ReadFully(splitStream);
ZipFile.Write(splitPdf, 0, splitPdf.Length);
}
pageCount++;
}
outputByteArray = memoryStream.ToArray();
}
Response.Clear();
Response.ContentType = “application/octet-stream”;
Response.AddHeader(“Content-Disposition”, “attachment; filename=Split.zip”);
Response.BinaryWrite(byteArrayObject);