Failed to load PDF document
<pre><code>//the func merges the src pdf with the memory stream, wherein the stream may contain 
//few othr src pdf streams in previous calls to this func
//in first cal, ms would be null
public static void MergePdf(MemoryStream ms, string srcFile)
{
    PdfReader reader = new PdfReader(srcFile);
    Document document = null;
    PdfWriter writer = null;
    int n = reader.NumberOfPages;
    if (document == null)
    {
        document = new Document(reader.GetPageSizeWithRotation(1));

        writer = PdfWriter.GetInstance(document, ms);

        document.Open();
    }
    PdfContentByte cb = writer.DirectContent;
    PdfImportedPage page;
    int rotation;

    int i = 0;
    while (i &lt; n)
    {
        i++;
        document.SetPageSize(reader.GetPageSizeWithRotation(i));
        document.NewPage();
        page = writer.GetImportedPage(reader, i);
        rotation = reader.GetPageRotation(i);
        if (rotation == 90 || rotation == 270)
        {
            cb.AddTemplate(page, 0, -1f, 1f, 0, 0,
                                     reader.GetPageSizeWithRotation(i).Height);
        }
        else
        {
            cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }
    }

}
</code></pre>

<p>I write the Memory stream, back to context.response.Outputstream; but the pdf doesnt load, the page 'Failed to load Pdf' results; Is there any problem in converting btwn memorystream and Pdf contents, or what may be the issue?</p>
