1 Reply Latest reply: Oct 29, 2010 1:22 AM by Frank Nimphius-Oracle RSS

    How to insert a word document or an RTF document into RichTextEditor?

      How to insert a word document or an RTF document into af:richTextEditor. I am using Apache POI for reading the Word document and getting its contents. I am able to display the whole content of the document except the table and image within the document. The data in the table is getting displayed as a string and not as a table inside the editor.

      Can we insert a word/RTF document into a rich text editor?
      Can we insert images into the rich text editor?

      The following is the code that I used. On clicking a button the word document has to be inserted into the <af:richTextEditor>.

      <af:richTextEditor id="rte1" autoSubmit="true"
      columns="110" rows="20">
      <af:dropTarget dropListener="#{SendEmail.richTextEditorDrop}">
      <af:dataFlavor flavorClass="java.lang.String"/>

      <af:commandButton text="Insert at position" id="cb2">
      <af:richTextEditorInsertBehavior for="rte1" value="#{RichTextEditorUtil.docFile}"/>

      Java Code: I am using Apache POI for reading the word document.

      import org.apache.poi.hwpf.HWPFDocument;
      import org.apache.poi.hwpf.extractor.WordExtractor;

      public String getDocFile() {
      File docFile = null;
      WordExtractor docExtractor = null ;
      WordExtractor exprExtractor = null ;
      try {
      docFile = new File("C:/temp/test.doc");
      //A FileInputStream obtains input bytes from a file.
      FileInputStream fis=new FileInputStream(docFile.getAbsolutePath());

      //A HWPFDocument used to read document file from FileInputStream
      HWPFDocument doc=new HWPFDocument(fis);

      docExtractor = new WordExtractor(doc);
      catch(Exception exep)

      //This Array stores each line from the document file.
      String [] docArray = docExtractor.getParagraphText();
      String fileContent = "";
      for(int i=0;i<docArray.length;i++)
      if(docArray[i] != null)
      System.out.println("Line "+ i +" : " + docArray);
      fileContent += docArray[i] + "\n";
      return fileContent;