We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Add pdf memory stream to zip file not working

Hi,
so I am creating a zip file of pdf documents, so I create  the pdf document( PdfDocument doc = new PdfDocument();)

//skipping code to convert to pdf from html here

After creating the pdf from html, I wrote the pdf into memory stream from below , then added it to a zip folder using the Iconic zip library.

But when I open the zip folder and click on the pdf file, it says 'adobe could not open the file'

What could the issue be? I thought I did everything properly

THanks for helping

MemoryStream stream = new MemoryStream();
  doc.Save(stream);
  zipFile.AddEntry("file.pdf", "", stream);
  return new ZipFileResult(zipFile, "TexasExport.zip");

1 Reply

KC Karthikeyan Chandrasekar Syncfusion Team November 2, 2012 05:13 AM UTC

Hi Martin,

Thank You for your interest in Syncfusion Products.

 

The error is due to the Stream Position.

When the document is saved in the stream(doc.Save(stream)), its current position moves to the end of file.

While creating the pdf file to add in to the zip folder the current position starts from EOF. So, the file created is empty.

Set the position to 0(zero) before creating the pdf file.

 

The code is as follows:

  MemoryStream stream = new MemoryStream();

            doc.Save(stream);

            stream.Position=0;             //This line should be added

            zipFile.AddEntry("file.pdf", "", stream);

  return new ZipFileResult(zipFile, "TexasExport.zip");

 

Please let us know if you have any concern.

 

Thanks,

Karthikeyan.C


Loader.
Live Chat Icon For mobile
Up arrow icon