title: How can I delete some pages from a pdf document using itextsharp?
body: <p>I am overwriting pages in a pdf file based on a user-specified sequence. I'm trying to set my code up in a way that selects the pages I want to keep from a file, store those pages as objects in memory, overwrite that same file completely, then write those pages back to the file, then append as needed by the user. </p>
  
  <pre><code>    PdfReader reader = new PdfReader("test.pdf");
      reader.SelectPages("1-5"));
      PdfStamper stamper = new PdfStamper(reader, new 
      FileStream("test.pdf", FileMode.Create));
  </code></pre>
  
  <p>The issue I'm running into is that the PdfStamper can't initialize because the file it wants to use for writing is already open for the PdfReader. How can I read the pages from the PdfReader into memory so that I can close it, then write to the same file after purging it?</p>