title: Trying to get a memory stream from a pdfstamper into a pdfreader but getting: "PDF startxref not found"
body: <p>I'm writing an app in c# that fills a bunch of pdf forms, concatenates them then puts in some page numbers.  I'm having difficulty with the memorystream result from the pdfstamper.  If I change the memorystream to a filestream it works fine but I don't want to use the filesystem.  I've created the following code snippet that reproduces my error:</p>
  
  <pre><code>    public static void TestStreams(string filepath)
      {
          PdfReader reader = new PdfReader(filepath);
          MemoryStream ms = new MemoryStream();
          PdfReader.unethicalreading = true;
          PdfStamper stamper = new PdfStamper(reader, ms);
          byte[] result = ms.ToArray();
          //The error is in the following line
          PdfReader reader2 = new PdfReader(result);
      }
  </code></pre>
  
  <p>The error is: </p>
  
  <pre><code>iTextSharp.text.exceptions.InvalidPdfException was unhandled
    HResult=-2146232800
    Message=Rebuild failed: trailer not found.; Original message: PDF startxref not found.
    Source=itextsharp
  </code></pre>
  
  <p>How can I fix it?</p>