`import React from "react";
import DocViewer, { DocViewerRenderers } from "react-doc-viewer";
//import * as pdfjsLib from 'pdfjs-dist/build/pdf';
import Doc from "./assets/test.docx";
// 设置 PDF.js worker 路径
//pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.16.105/pdf.worker.min.js";
function FileViewer() {
const docs = [
{ uri: require("./assets/test.docx") ,fileType: "docx"}, // Local File
];
return <DocViewer
documents={docs}
pluginRenderers={DocViewerRenderers}
/>;
}
export default FileViewer;`
Description:
I encountered an error when using the latest react-doc-viewer to preview PDF files. I managed to fix it by adding the following configuration for pdfjs-dist:
import * as pdfjsLib from 'pdfjs-dist/build/pdf';
pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.16.105/pdf.worker.min.js";
However, I cannot preview Office files (docx, xlsx, pptx). The console shows these errors:
GET https://view.officeapps.live.com/op/zh-CN/strings.js 403 (Forbidden)
My Question:
- Could you please tell me which version of
react-doc-viewer can successfully preview pptx, xlsx, and docx files?
- I followed the documentation but still couldn't get it to work, which is very confusing. Are there any known working configurations for Office files?
- If this is a persistent issue with the library, are there any other recommended libraries that can serve as a reliable alternative for previewing these file types (especially docx, xlsx, pptx) in a React application?
Thank you for your help!
`import React from "react";
import DocViewer, { DocViewerRenderers } from "react-doc-viewer";
//import * as pdfjsLib from 'pdfjs-dist/build/pdf';
import Doc from "./assets/test.docx";
// 设置 PDF.js worker 路径
//pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.16.105/pdf.worker.min.js";
function FileViewer() {
const docs = [
{ uri: require("./assets/test.docx") ,fileType: "docx"}, // Local File
];
}
export default FileViewer;`
Description:
I encountered an error when using the latest
react-doc-viewerto preview PDF files. I managed to fix it by adding the following configuration forpdfjs-dist:However, I cannot preview Office files (docx, xlsx, pptx). The console shows these errors:
GET https://view.officeapps.live.com/op/zh-CN/strings.js 403 (Forbidden)My Question:
react-doc-viewercan successfully preview pptx, xlsx, and docx files?Thank you for your help!