Skip to content

Facing 403 Error with Office Files Preview (docx/xlsx/pptx) and AbortError #174

@521guyu

Description

@521guyu
Image

`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:

  1. GET https://view.officeapps.live.com/op/zh-CN/strings.js 403 (Forbidden)

My Question:

  1. Could you please tell me which version of react-doc-viewer can successfully preview pptx, xlsx, and docx files?
  2. 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?
  3. 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!


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions