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.
Unfortunately, activation email could not send to your email. Please try again.

Add pdf memory stream to zip file not working

Thread ID:

Created:

Updated:

Platform:

Replies:

105481 Oct 29,2012 02:47 PM Nov 2,2012 01:13 AM ASP.NET Web Forms (Classic) 1
loading
Tags: PDF
Martin White
Asked On October 29, 2012 02:47 PM

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");

KarthikeyanC [Syncfusion]
Replied On November 2, 2012 01:13 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;