Use a document viewer component for react like react-doc-viewer:- https://www.npmjs.com/package/react-doc-viewer
codesandbox:- https://codesandbox.io/s/zvk4j
Answer from Alan Shajan Mattathil on Stack Overflowreactjs - All kinds of document viewer in react - Stack Overflow
Newest 'react-doc-viewer' Questions - Stack Overflow
reactjs - react-doc-viewer won't show Docx file, shows blank - Stack Overflow
Want to create a custom document viewer.
Videos
» npm install react-doc-viewer
» npm install @cyntler/react-doc-viewer
The docx file MUST be a publicly accessible url.
Local files will NOT work because the docx renderer (which uses an external service) needs to be able to access the url.
import DocViewer, { DocViewerRenderers } from "@cyntler/react-doc-viewer";
function App() {
return (
<div style={{ height: "100vh", width: "100vw" }}>
<DocViewer
documents={[{ uri: "http://your-publicly-accessible-url.docx", fileType: "docx" }]}
pluginRenderers={DocViewerRenderers}
/>
</div>
);
}
I found this GitHub issue very helpful Docx not working GitHub Issue
Adding a File type worked for me, { uri: require("./Dynamic_tabs.docx"), fileType: 'docx' },
I am asked to create a custom document viewer . ( doc types include - csv's , pdf's , xlsx , ppt's etc. etc.. all the common document types )
I used these 2 libraries :
react-doc-viewer
cyntler/react-doc-viewer
Both support multiple file types , but the '.doc' and '.docx' types are supported only with public URL's
( a few more file types are also supported only with public URL's ).
In my use case I will be using S3 Links to fetch the document and render them.
Since s3 links are private ( and we don't intend to change this ). What can I use to render the doc and docX type?
Is there any other alternative to those libraries ( free ) that I can use where It renders multiple file types?
Reference of roughly what I need to create.