PD4ML v4 Forums PD4ML v3 Archived Forums (Read Only) General questions / FAQ .NET Generating PDF into MemoryStream instead of the file

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26453

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

    #28206

    Exactly the same thing happens to me

    #28207

    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

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘General questions / FAQ’ is closed to new topics and replies.