title: How to append a PDF file to an existing one with iText?
body: <p>In an application I am trying to append multiple PDF files to a single already existing file. Using iText I found this</p>
  
  <p>Using iText I found this tutorial, which, in my case doesn't seem to work.</p>
  
  <p>Here are some ways I've tried to make it work. </p>
  
  <pre><code>String path = "path/to/destination.pdf";
  PdfCopy mergedFile = new PdfCopy(pdf, new FileOutputStream(path));
  
  PdfReader reader;
  for(String toMergePath : toMergePaths){
      reader = new PdfReader(toMergePath);
      mergedFile.addDocument(reader);
      mergedFile.freeReader(reader);
  
      reader.close();
  }
  
  mergedFile.close();
  </code></pre>
  
  <p>When I try to add the document logcat tells me that the document is not open.</p>
  
  <p>But, <code>pdf</code> (the original document) is already open by other methods, and closed only after this one. And, <code>mergedFile</code> is exactly like in the tutorial, which, I   believe, must be right.</p>
  
  <p>Did anyone experience the same problem? Otherwise, do anyone know a better method to do what I want to do?</p>
  
  <p>I've seen other solutions copying the bite from one page and append them to a new file but I'm affraid this will "compile" the annotations which I need.</p>
  
  <p>Thank you for your help,</p>
  
  <p>Cordially,</p>
  
  <p>Matthieu Meunier</p>