4

HI everyone i am doing file handling in my spring MVC Application, i need to display Word file (.doc, .docx) file in my browser instead of downloading..

i am using this code for displaying file in browser,..

response.setHeader("Content-Disposition", "inline; filename=\"%s\"",
                    downloadFile.getName()");

with this code PDF, IMAGE File, and TXT Files are showing in browser but not word file,

can you please help me how to do this ? i have go through different solutions in stackoverflow and google but i cannot find any thing.

PS: i don't want google docs for displaying word file.

Ahmad
  • 1,462
  • 5
  • 17
  • 40
  • it's a little hard to show WordDocument on browser because it is not supported by default like PDF, IMAGE, TXT. I already try this in one of my project but finnally i convert the doc or docx to PDF (inside my project) and show the PDF. to show worddocument, google doc is the best way – Aroniaina Sep 19 '16 at 10:49
  • hmm but my requirement is to display word file – Ahmad Sep 19 '16 at 11:02

1 Answers1

0

This is entirely up to the browser, most of which don't have built-in support for Word documents. You've already given it the hint, and it will decide how (or even whether) it can handle it.

The only other approach would be to use an inline JavaScript-based viewer, similar to the one that Google Docs does use, but that would change the nature of the response from "here is a file" to "here is a Web application that I'll preload with content".

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • you mean viewerjs.org is capabale to display word files in browser ? actually i want to display files in browser without internet, that is why i do not want to use google docs – Ahmad Sep 19 '16 at 11:07
  • its very hard and somone tell me when I search about it : "Even if google can't "! google use JS to display it but dont use byte of the file or his stream! – Aroniaina Sep 19 '16 at 11:10
  • if you find how to do it without converting or using remote JS, please show us! – Aroniaina Sep 19 '16 at 11:41