title: Populate Multiple PDFs
body: <p>I am using <code>itextsharp</code> to populate my PDFs. I have no issues with this. Basically what I am doing is getting the PDF and populating the fields in memory then passing back the <code>MemoryStream</code> to be displayed on a webpage. All this is working with a single document PDF.</p>
  
  <p>What I am trying to figure out now, is merging multiple PDFs into one <code>MemoryStream</code>. The part I cant figure out is, the documents I am populating are identical. So for example, I have a <code>List&lt;Person&gt;</code> that contains 5 persons. I want to fill out a PDF for each person and merge them all into one, in memory. Bare in mind I am going to fill out the same type of document for each person.</p>
  
  <p>The problem I am getting is that when I try to add a second copy of the same PDF to be filled out for the second iteration, it just overwrites the first populated PDF, since it's the same document, therefore not adding a second copy for the second <code>Person</code> at all. </p>
  
  <p>So basically if I had the 5 people, I would end up with a single page with the data of the 5th person, instead of a PDF with 5 like pages that contain the data of each person respectively.</p>
  
  <p>Here's some code...</p>
  
  <pre><code>MemoryStream ms = ms = new MemoryStream();
  PdfReader docReader = null;
  PdfStamper Stamper = null;
  List&lt;Person&gt; persons = new List&lt;Person&gt;() {
     new Person("Larry", "David"),
     new Person("Dustin", "Byfuglien"),
     new Person("Patrick", "Kane"),
     new Person("Johnathan", "Toews"),
     new Person("Marian", "Hossa")
  };
  
  try
  {
     // Iterate thru all persons and populate a PDF for each
     foreach(var person in persons){
        PdfCopyFields Copier = new PdfCopyFields(ms);
        Copier.AddDocument(GetReader("Person.pdf"));
        Copier.Close();
  
        docReader = new PdfReader(ms.ToArray());
        Stamper = new PdfStamper(docReader, ms);
        AcroFields Fields = Stamper.AcroFields;
        Fields.SetField("FirstName", person.FirstName);
     }
  }catch(Exception e){
    // handle error
  }finally{
     if (Stamper != null)
     {
        Stamper.Close();
     }
     if (docReader != null)
     {
        docReader.Close();
     }
  }
  </code></pre>