title: Add text in MS Word doc using apache POI
body: <p>I have been trying to edit different types of documents using Apache POI. The script should handle both extensions <code>.doc</code> and <code>.docx</code>. I could successfully edit the <code>.docx</code> file using <code>XWPF</code> api and the required text was added at the end of the docx file. </p>
  
  <p>For editing <code>.doc</code> files(which include <strong>header</strong>, <strong>footer</strong> and a few <strong>paragraphs</strong>), following script is used, which use <code>HWPFDocument</code>.</p>
  
  <pre><code> FileInputStream fis = new FileInputStream(args[0]);
  
   POIFSFileSystem fs = new POIFSFileSystem(fis);
   HWPFDocument doc = new HWPFDocument(fs);
  
   Range range = doc.getRange();
   CharacterRun run = range.insertAfter("FROM SEHWAGGG A FOUUURRRRRR");
   run.setBold(true);
   run.setItalic(true);
  </code></pre>
  
  <p>The script works fine with normal documents which does not have <strong>header</strong> and <strong>footer</strong>. But seems that the issue appears with complex documents. It insert text, but in between the <strong>paragraphs</strong> (and at the beginning using <code>insertBefore()</code>). There are no text replacements required, just have to put the text at the end of the document. I searched similar scripts but  most of them handle text replacement. </p>
  
  <p>How can I add the text at the end, after all paragraphs? </p>