How do I render a Word document (.doc, .docx) in the browser using JavaScript?

后端 未结 10 778
难免孤独
难免孤独 2020-11-22 07:32

I have successfully done code to display a PDF file in the browser instead of the \"Open/Save\" dialog. Now, I\'m stuck trying to display a Word document in the browser. I w

10条回答
  •  花落未央
    2020-11-22 08:02

    There seem to be some js libraries that can handle .docx (not .doc) to html conversion client-side (in no particular order):

    • https://github.com/lalalic/docx2html — docx to html, most elements are supported

    • https://github.com/mwilliamson/mammoth.js — supports headings, lists, tables, endnotes, footnotes, images and text boxes

    • https://www.npmjs.com/package/docx2html — Converts DOCX documents to HTML in the browser or nodejs

    • https://github.com/artburkart/docx2html — apparently, works in the browser

    Note: If you are looking for the best way to convert a doc/docx file on the client side, then probably the answer is don't do it. If you really need to do it then do it server-side, i.e. with libreoffice in headless mode, apache-poi (java), pandoc or whatever other library works best for you.

提交回复
热议问题