title: VB.Net Merge multiple pdfs into one and export
body: <p>I have to merge multiple PDFs into a single PDF. </p>
  
  <p>I am using the iText.sharp library, and collect converted the code and tried to use it (from <a href="https://stackoverflow.com/questions/15925616/how-to-merge-multiple-pdf-files-generated-in-run-time/15945467?noredirect=1#comment53906468_15945467">here</a>)
  The actual code is in C# and I converted that to VB.NET.</p>
  
  <pre><code> Private Function MergeFiles(ByVal sourceFiles As List(Of Byte())) As Byte()
      Dim mergedPdf As Byte() = Nothing
      Using ms As New MemoryStream()
          Using document As New Document()
              Using copy As New PdfCopy(document, ms)
                  document.Open()
                  For i As Integer = 0 To sourceFiles.Count - 1
                      Dim reader As New PdfReader(sourceFiles(i))
                      ' loop over the pages in that document
                      Dim n As Integer = reader.NumberOfPages
                      Dim page As Integer = 0
                      While page &lt; n
                          page = page + 1
                          copy.AddPage(copy.GetImportedPage(reader, page))
                      End While
                  Next
              End Using
          End Using
          mergedPdf = ms.ToArray()
      End Using
  End Function
  </code></pre>
  
  <p>I am now getting the following error:</p>
  
  <blockquote>
    <p>An item with the same key has already been added.</p>
  </blockquote>
  
  <p>I did some debugging and have tracked the problem down to the following lines:</p>
  
  <pre><code>copy.AddPage(copy.GetImportedPage(reader,
  copy.AddPage(copy.GetImportedPage(reader, page)))
  </code></pre>
  
  <p>Why is this error happening?</p>