title: Converting from HWPFDocument to XWPFDocument or vice versa
body: <p>I have a Word document, where I have to replace text and save this document in Oracle database, in PDF format. Have someone any idea how to resolve this?</p>
  
  <pre><code>String inputFilename = "/root/GeneratorUmow/web/WEB-INF/umowy/kkb/wniosekozaciag.docx";
     try(InputStream is = new FileInputStream(inputFilename)) {
        dbd = new DokumentyBlobDAO();
        db.setNazwaPliku("Wniosek_o_zaciagniecie.pdf");
        db.setTypDokuemntu(876990);
        if(du.getTypKlienta() == S_ID_Lead_Partner_Typ_Klienta_KKB) { 
           POIFSFileSystem fs = null;            
           fs = new POIFSFileSystem(is);
           HWPFDocument doc = new HWPFDocument(fs); //funkcja zamyka inputstream
           Range range = doc.getRange();
           range.replaceText("my&amp;&amp;nazwa&amp;&amp;firmy", "KAKAOWY SZATAN");
           //konwersja na pdf
                  FileOutputStream fos = new FileOutputStream(pathToDirectory + File.separator + folderName+File.separator + "wniosekzaciagniecie.docx");
                  doc.write(fos);
  
  
                  String inputChangeFile = pathToDirectory+ File.separator +folderName+File.separator+"wniosekzaciagniecie.docx";
                  InputStream inputstream = new FileInputStream(inputFilename);
                  length = inputChangeFile.length();
                  System.out.println("dlugosc lancucha " + length);
  
                  XWPFDocument document = new XWPFDocument(inputstream);            
                  System.out.println("message3");
                  PdfOptions options = PdfOptions.create();
                  PdfOptions options = PdfOptions.create().fontEncoding("windows-1250");
                  System.out.println("message4");
                  OutputStream out = new FileOutputStream(new File(pathToDirectory+ File.separator +folderName+File.separator+"kakaowyszal.pdf"));
                  PdfConverter.getInstance().convert(document, out, options);
                  System.out.println("message5");
  
  
  
              }
          }
          catch( Exception ex){
              System.out.println("err"  + ex);
              return -1;
          }
  </code></pre>