Search code examples
filejspincludedoc

how to add content of word doc file in jsp file using include action?


I am trying to include the text content of microsoft word file in my jsp file.... I am not able to figure out the solution.


Solution

  • It is not possible to include proprietary/platform-specific formats in a HTML page without a good plugin in the webbrowser. Besides, in case of MS Office documents you're heavily dependent on the client machine whether it would work or not. Not every Windows machine has MS Office installed and even then not every of them has a browser plugin for that. This ain't going to work in non-Windows machines.

    So you have basically two options:

    1. Programmatically extract the Word document yourself and display contents as HTML.
    2. Convert the Word document to a more standard format supported by a majority, like PDF.

    If you prefer 1, you could use the aforementioned (and memory hogging) Apache POI for that. Or you could use the more memory efficient (and OOo based) JODConverter for that. It can even convert Word documents to HTML or even to PDF so that you've a solution for option 2 as well. In this case you can just use <iframe> or <object> tags to display the PDF embedded in HTML.