React can preview files word, pdf, docx format online

tags: React

React online preview word, file pdf, docx format, look down below

I do not know why this feature, check the Baidu long time to find a component, the codes react-file-viewer below


1, the first to use npm / yarn / cnpm download this package

npm install react-file-viewer

2, this package is introduced in the assembly

// This component is introduced
import FileViewer from 'react-file-viewer';

3, using this component

render() {
        let { top, file } = this.state;
        let { play, sonstate } = this.props
        var index = file.lastIndexOf(".");
        var type = file.substr(index + 1);
        return (
            <div>
                <div className="top" style={{ display: play ? 'flex' : 'none' }}>
                    <div className="all" >
                        <div className="allname">
                            <div className="topall"><Button style={{ opacity: '0' }}>shut down</Button><div></div><Button onClick={() => {
                                sonstate(false)
                                this.setState({ top: false, file: '' })
                            }}>shut down</Button>
                            </div>
                            {/ * Use of this component * /}
                            <FileViewer fileType={type}
                                filePath={file}
                                onError={this.onError}
                                errorComponent={Error}
                                unsupportedComponent={Error}
                            />
                        </div>
                    </div>
                </div>
            </div>
        )
    }

3, pay attention to the use of this rule component

Note that this module is most suitable for 16+ reaction. If you are using React <16, you may need to use the 0.5 version. npm install [email protected].

There is a major component of React FileViewer, which uses the following items:

fileTypestring: resource type to be displayed (for example, one file format support 'png'). Incoming unsupported file types will result in displays unsupported file type messages (or custom components).

filePath string: url resources FileViewer displayed.

onErrorfunction [Optional]: Gets or rendering function that will be called when an error occurs when the requested resource in the file viewer. You can pass callback logging utility here.

errorComponent react element [Optional]: Component presented when an error occurs, rather than the default error component and react-file-viewer packaged together.

unsupportedComponent react element [Optional]: Components presented in the case do not support the file format.

4. Note that this component supported formats

  • Image: png, jpeg, gif, bmp, 360 of the image comprising
  • PDF format
  • CSV
  • XSLX
  • DOCX
  • Video: mp4, webm
  • Audio: mp3

ps: of course, you can look at this linkhttps://www.npmjs.com/package/react-file-viewer

Intelligent Recommendation

Java implementation Word Transfer PDF online preview format

Java implementation Word Transfer PDF online preview format This function involved in the project, survived some programs, stepped on some pits, and summarized here. Java turns a lot of solutions, but...

The front -end realization of online preview Word (docx), PDF, Excel type file

Implementation After finding the online implementation plan, the effect looks good. Put it in the table below. Some of them can be introduced directly in the Vue through the NPM. Document format Old o...

Word Online Preview (with DOC, DOCX, etc.)

Idea: This online preview is encountered in the project. Most of the solutions are Word Transfer PDF and then call PDFJS to complete page preview. 1. Introducing POM dependence   The code! contro...

Nuxt.js implements online preview of word, excel, ppt, and pdf files

file-preview Online preview of word, excel, ppt, and pdf files.View Technology used Nuxt.js express element-ui typeorm pdf.js Online preview of word, excel, pptMicrosoft interface documentation node-s...

Online Preview upload doc, pdf and other word files

Demand project: the background upload some doc or pdf and other documents required front-end for online preview these files. Ideas: the interface will return to a path, combining <embed /> tag, ...

More Recommendation

jsp realizes online preview of pdf, word, xls, ppt and other files

Recently, I am working on a shared digital platform, and record some of the functional knowledge involved. , Other tutorials are written too old, and may no longer be applicable today. 1. JSP realizes...

Pdf conversion of Word and Excel files through Aspose, realizing online preview

Solution: 1. Use the conversion function provided by AsposeCells and AsposeWords related Jar packages to convert Excel and Word type documents into Pdf files and store them in the current project dire...

HTML preview Word, PDF, Excel, TXT, pictures and other files online.

Recently, a need is to preview various files online. If you find a fee, you will be connected to the external network. Finally, I found an open source project when I wandered myself. The specific proc...

Django implements online preview PDF, Word, XLS, PPT and other files

Django implements online preview PDF, Word, XLS, PPT and other files 1. Add files to static resources 2, configure view functions views.py 3、html<object type="application/pdf" data='../.....

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top