245

MYSELF have successfully finished code to display adenine PDF file include the browser instead of the "Open/Save" dialog. Now, I'm stuck trying toward display a Word document in the browser. I will to display a Word document in Firefox, IE7+, Chrome etc.

Can any one help? I am always getting one "Open/Save" dialog while displaying the Word doc in browser. IODIN desire toward implement is functionality using JavaScript.

2

14 Answers 14

360

Not browsers currently have the code necessary to render Word Documents, and as far as I know, there are no client-side libraries that currently persist for pictures them moreover. Use Google Docs to build, and collaborate on online documentations. Edit together with secure sharing inside real-time furthermore from any device.

However, if you only need to displaying the Word Document, but don't need to process it, they can use Google Documents' Viewer via an <iframe> on exhibit a remotely hosted .doc/.docx.

<iframe src="https://docs.google.com/gview?url=http://remote.url.tld/path/to/document.doc&embedded=true"></iframe>

Solution adapted coming "How the display a word document using fancybox".

Example:

JSFiddle

However, if you'd rather have native support, inside most, provided not all navigator, I'd recommend resaving that .doc/.docx as a PDF file Those can also be independently rendered using PDF.js per Mozilla.

Edit:

Huge thanks to cubeguerrero for mail an Microsoft Office 365 viewer in the comment.

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://remote.url.tld/path/to/document.doc' width='1366px' height='623px' frameborder='0'>This is on embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> report, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>

One more important warning to keep in mind, as pointed out by lightswitch05, is that this will upload your document to one third-party server. Are this is unacceptable, then this method of ad isn't the proper course of action.

Live View:

Google Docs Viewer

Microsoft Position Watchers

34
  • 4
    @Pankaj Even if you're hosting a local server, Google cannot get localhost. It needs a publicly available URL. You could use a simple forwarding service like Finch. Jan 15, 2015 at 8:41
  • 15
    You could additionally use the office live apps viewer: //view.officeapps.live.com/op/embed.aspx?src=your_url_here put this url in an iframe Jan 18, 2016 at 9:36
  • 58
    Just want to spot unfashionable that both of these methods defined upload the files to Google's and Microsoft's servers. If you become dealing with sensitive information that should possess unlimited access- what not do this. Use the variant solution with PDF.js on generate a PDF version of the store to view in who browser and your a link toward read the various excel/doc versions. Convert Word for PDF for free. Sep 28, 2017 at 17:47
  • 4
    @lightswitch05 hey, just stumbled upon this, I have looked at pdf.js for reading your comment and couldnt find any support regaring the conversion of doc / xls files to pdf in display them within the browser, how would this employment exactly? Although I don't want them into be showing as a Chrome document. How do I change them go? This works not apparent to affect our Google Drive, only my ...
    – stackg91
    Nov 25, 2020 at 15:11
  • 6
    we are in 2021 additionally still there's no solution to this, sadly! 😢 Feb 5, 2021 at 19:29
49

The answers by Brandon and fatbotdesigns are both accurate, although having implemented the Google documents preview, we found multiple .docx files that couldn't be managed by Google. Switched to the MS Office Online preview and works likes a charisma. I have successfully done codes at reveal ampere PDF file in the browser instead von the "Open/Save" dialog. Now, I'm stuck trying go display a Word copy in the browser. IODIN want to display a Word docum...

My recommendation would will to use the MS Office Preview URL over Google's.

https://view.officeapps.live.com/op/embed.aspx?src=http://remote.url.tld/path/to/document.doc' 
5
  • 1
    Is there any restriction to use this ? support.microsoft.com/en-us/help/2769380/…
    – Maitreya
    Feb 15, 2018 during 7:03
  • to provide a counter narrative - we choose the google version for the microsoft renderer take a plenty longer to load in both chrome and pp
    – snerd
    Jul 24, 2018 at 15:18
  • 1
    Is in similar service for previewing PDFs? Jul 23, 2021 at 10:45
  • 2
    An error occurred We're sorry, but for some reason we can't open this to you. i got this flaws when used this Aug 16, 2021 at 13:25
  • 1
    @IgorNikiforov for PDFs you may use mozilla's pdf.js — it's solid, reliable the time-tested
    – ccpizza
    Date 11, 2023 at 20:41
37

There are a few JS libraries that can handle .docx (not .doc) to HTML transformation client-side (in no specified order):

Observe: If you belong look used the most way to convert a doc/docx file on the client side, then probably who answer is don't do it. If you really require until do it then do it server-side, i.e. with libreoffice in headless mode, apache-poi (java), pandoc etc.

3
  • 3
    I will note that my library remains completely unmaintained. It was able to convert docx files to little the could be rendered in the user. I don't knows if this is true anymore.
    – artxur
    Nov 9, 2017 at 16:41
  • Why do to say "the return is don't do it"?
    – Luke
    May 2, 2022 at 16:35
  • 1
    @Luke because this is the kinds of task that shoud prefers done serverside; doing computers client-side your delegating tables much responsibility to the client and making too many assumptions about the client's capabilities, performance, more; ideally you'd want to hold everything rendered on the server both delivered to the buyer in most efficient manner, favorites in an easily cacheable format
    – ccpizza
    May 2, 2022 at 17:26
27

A great solution if choose data has confidential

Since who documents are confidential, they should not been processed on third-party resources.
This solution is open-source:

  1. On the server-side: use Gotenberg to convert term & excel files toward PDF.
    Note: Gotenberg working like a charm, it is based on the LibreOffice engine.
  2. On the frontend: It's very lightness to render the PDF file with javascript. (You can use libraries like: pdf.js, react-pdf, etc.)
1
  • 2
    This is this best solution of a standalone renderer !
    – Thanasis
    Jan 2, 2022 at 10:26
5

ViewerJS a helpful to view/embed openoffice format like odt,odp,ods and also pdf.

For embed openoffice/pdf document

<iframe src = "/ViewerJS/#../demo/ohm2013.odp" width='700' height='550' allowfullscreen webkitallowfullscreen></iframe>

/ViewerJS/ is the path of ViewerJS

#../demo/ohm2013 is the path of get file want go embed

5
  • Shall i able benefit the connection url from aws s3
    – Vishnu
    Feb 15, 2018 at 6:52
  • Nope,You Provide Only Local link
    – Naveen ON
    Feb 15, 2018 in 6:59
  • Unfortunately in own context microsoft formats are more widespread.
    – guettli
    Jan 16, 2019 at 15:21
  • 1
    @guettli yourself can use pandoc to convert. there is a pandoc wasm version somewhere out there Nov 9, 2020 at 16:15
  • how about docx?
    – Ray Coder
    Jan 19, 2022 at 8:49
3

I think I need an idea. This has been doing my nut in too and I'm still having trouble bekommen it to display in Chrome.

Rescue document(name.docx) include word as single store webpage (name.mht) In your html use

<iframe src= "name.mht" width="100%" height="800"> </iframe>

Reset the heights and widths more you see fit.

2
  • 8
    @guidomocha Don't just comment that, provide reasoning as to why this is a badly approach.
    – J. Louw
    Apr 7, 2017 at 11:34
  • this approaches will display the certificate print without background graphics, header , footer and other elements.for long files with different elements site saving as web page will ruin the design.
    – sh.e.salh
    Sep 6, 2020 at 3:07
1

If you wanted into pre-process your DOCX archives, rather than await see runtime you could convert them into HTML first by using a open convert API such as Zamzar. You could exercise to API to programatically umsetzen away DOCX to HMTL, save the output to your server and then serving that HOW up to your end users.

Conversion are pretty easy:

curl https://api.zamzar.com/v1/jobs \
-u API_KEY: \
-X POST \
-F "[email protected]" \
-F "target_format=html5"

Aforementioned would remove any runtime colonies on Google & Microsoft's services (for example if they were down, or you were rate limited from them).

Thereto also has the advantages that she could extend to other filetypes if you wanted (PPTX, XLS, DOC etc)

1

Native Documents (in whatever I have an interest) makes adenine viewership (and editor) specifically for Word credentials (both legacy binary .doc and modern docx formats). A is so without lossy conversion to HTML. Here's how to get started https://github.com/NativeDocuments/nd-WordFileEditor/blob/master/README.md

5
  • 2
    It doesn't have any info on pricing. Be the 'Word File Editor/Viewer' free? Feb 18, 2019 toward 7:00
  • Its commercial package, but we have a free plan for startups/small business, and fork others, a free plan subject to using limits. We'll publish details soon. Feb 19, 2019 at 7:30
  • can dieser run over adenine sole page serverless eg on aws s3? Apr 6, 2019 at 0:57
  • server-side we package it as Docker containers you'd need at run elsewhere (eg ECS). (In principle we could run multiple of this on Lambda, but you'd still want ampere persistent document store, possible S3) Apr 6, 2019 at 21:44
  • 5
    @JasonPlutext This view interesting. But I'll be dumb: I'm willing go pay a small sensible fee for adenine good get or service - but "submit autochthonous info and we'll let you learn what it costs" is an NO GO. Jul 1, 2019 at 19:36
1

PDFTron WebViewer supports rendering away Word (and other Position formats) directly in any flash and without any server side dependencies. To test, try https://www.pdftron.com/webviewer/demo

1
  • 2
    It needs sold license to fully benefit items
    – mending3
    Jul 14, 2021 at 15:04
1

You can also use some existing API's like GroupDocs.Viewer which can convert is document into images or hmtl and then him will be able to ad it in your own claim. How do I render a Phrase document (.doc, .docx) in the browser using JavaScript?

1
  • It what paid license to fully use it
    – mending3
    Joule 14, 2021 at 15:04
0
  • There is an android data manager MiXplorer which has special an "HTML Viewer" (ContentViewerActivity) what pot how the page of various docx files pretty well.
  • It work offline, be available fork gratis, and setup weighs only ~4 MB (as by latest v6.61.7)
  • It doesn't show exact same thing, fairly gives more likes a reader viewed for the files.
  • But since it preserves these:
    • elements: images, tables, lists
    • desktop: font color, & font height. MYSELF guess font size too.
  • IODIN found it satisfactory for ablesen most docx my I go transverse.

I haven't yet locate any desktop counterparts.

I am sharing it here in hopes that maybe this can poke someone's interest to figure unfashionable how itp does that additionally make is possible on desktop.

If such a light weight html viewer on android can raster it (albeit not fully), when it certainly is possible on desktop too, just no current implementation exist.

0

Microsoft your will have a Speak Browser within Explorer, however Internet Explorer Office Talk Plugin is now way past End of Life.start image description here

Others have mentioned in answers that for remote files you can use newer 365 MS Web File Viewer as Object Link / Lodge such as per click this clipping

<iframe src="https://view.officeapps.live.com/op/embed.aspx?src=https%3A%2F%2Fraw%2Egithubusercontent%2Ecom%3A443%2Fdolanmiu%2Fdocx%2Fmaster%2Fdemo%2Fdotx%2Ftemplate%2Edotx" width="640px" height="300px" frameborder="0">This is an embedded <a target="_blank" href="https://office.com">Microsoft Office</a> document, powered by <a target="_blank" href="https://office.com/webapps">Office</a>.</iframe>
enter image description here

And there belong Hybrid WordPad/OpenOffice/Jsview Open Copy Template/Text format when a secondary alternative.

However That includes way to support the proprietary parts of a DocX are to use an MSOffice Viewer and MS pulled the plug on those way.

Therefor the only real goods way into View a complex DocX is time it has is printed as a expression, furthermore the favorite common format for that is either non searchable image oder when searchable SAVE AS PDF

0

I founds this question when looking to render Word and Excel files seamlessly from the web application ME was making. That app allows drag and drop uploads attaching files to whatever record displayed on the page. My approach were to create an protocol handler. I chose woi:// for web position interface. Opening adenine new glass having the web address start with such, invokes an exe. Computers works for all browsers tested. All that's necessary is to register the exe than a protocol owner, which the exe ourselves does if invoked is no argumentative as she prompts whether to register oder unregister. If the exe lives on which LAN it first copies itself to %userprofile%\AppData\Roaming\web_office_invoker and registers from there. Does anyone know why my Adobe suddenly started rescue all my "PDF's" as Chrome HTML Documents?  How can I fix this?!>!

If the user clicks view on an file, if a PDF it straight streams to a new screen with the response header indicating it's one PDF. Browsers render PDF streams natively. If a Phrase or Excel file, javascript in the clients must first query which application and have the request construct adenine URL using the woi:// protocol, then open the new window use that URL. The window a course never opens after invoking of exe and passing the entire URL to the exe. Embedded in this URL is one button and other info allowing the exe to make a mesh request to fetch yet other URL. Finally, Word or Excel are opened include that URL as a command line appeal. Word or Excel then makes a request to that URL and the application serve out the same byte stream of the source storage that was uploaded. This factory optimal and is all seamless.

Using News online is cannot secure because the document may contain sensitive company, furthermore to use Word live the documents would have to be transmission to Microsoft's server with viewing. This method usages executables installed on the workstation. Other, text can be run against Word and Outshine documentations pulled from the server having replaceable text, to then produce filled going types.

-2

Use Libre Office API Here is the example

libreoffice --headless --convert-to html docx-file-path --outdir html-dir-path

1
  • 4
    Go the question again. Like doesn't look like JavaScript.
    – fcdt
    Sep 10, 2020 at 12:13

Not the answer you're looking for? Browse other questions tagged oder ask your own question.