PDF Generating Tool Support Forum

HOME   Login   Register    Search




  Subject: .NET Generating PDF into MemoryStream instead of the file
   PostPosted: 15 Sep 2010, 18:40 
I'm trying to generate PDF file in memory using MemoryStream. But MemoryStream is closed and unaviable for reading after render method is completed.

I have seen an example on how to do it in Java using ByteArrayOutputStream but no example was provided in .NET.

Thank you
...
MemoryStream msPDF = new MemoryStream();
msPDF.Seek(0,System.IO.SeekOrigin.Begin);
pd4ml.render(msHTML,msPDF, new System.Uri("http://localhost/cf"));
byte[] baPDF = new byte[msPDF.Length];//this line produces an exception
msPDF.Read(baPDF,0,(int) msPDF.Length);


  Subject: Re: .NET Generating PDF into MemoryStream instead of the file
   PostPosted: 13 May 2011, 09:10 
Exactly the same thing happens to me


  Subject: Re: .NET Generating PDF into MemoryStream instead of the file
   PostPosted: 13 May 2011, 10:09 
This is a common problem with MemoryStream usage in code ported from java.

Try this workaround (it works fine for me):
http://connect.microsoft.com/VisualStudio/feedback/details/164680/streamwriter-incorrectly-disposes-underlying-stream
Basically decorate the underlying memory stream (the argument to StreamWriter) as:
streamWriter(new NonDisposingStreamDecorator(memoryStream))

Alex



[Reply]     [ 3 posts ] 

cron
Copyright ©2004-10 zefer|org. All rights reserved. Bookmark and Share