0.0.2 • Published 4 years ago

@lemon-clown-wpg/react-pdf-viewer v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

npm version npm download npm license

A pdf viewer

pdf-viewer.png

See sourcecodes in github to get more information.

Usage

  • Install

    yarn add @lemon-clown-wpg/react-pdf-viewer
    # you aslo should install peerDependencies if the terminal prompts for a warnning
  • Use in React project

    import React from 'react'
    import ReactDOM from 'react-dom'
    import { PDFViewer } from '@lemon-clown-wpg/react-pdf-viewer'
    import '@lemon-clown-wpg/react-pdf-viewer/lib/esm/index.css'
const pdfStyle: React.CSSProperties = {
  width: '100vw',
  height: '100vh',
}


// index.tsx
ReactDOM.render(
  <PDFViewer
    style={ pdfStyle }
    fileUrl="/files/demo.pdf"
  />
  , document.getElementById('root')
)
```

Options

propertyrequiredtypedefault
fileUrltruestring
fileNamefalsestring/(?:[^/\\]*[/\\])?([^/\\]+?)(?:#[\s\S]*)?$/.exec(fileUrl)[1] || ''
directionfalse'ltr' | 'rtr''ltr'
MIN_SCALINGfalsenumber0.50
MAX_SCALINGfalsenumber4.00
ZOOM_STEPfalsenumber0.10
selectOptionsfalsenumber[] 0.50, 0.75, 1.00, 1.25, 1.50, 2.00, 3.00, 4.00
onDocumentLoadErrorfalseFunctionundefined
onDocumentLoadSuccessfalseFunctionundefined
  • fileUrl: url of pdf file
  • fileName: filename of pdf file
  • direction: the text direction
  • MIN_SCALING: minimum scaling
  • MAX_SCALING: maximum scaling
  • ZOOM_STEP: the size of the zoom step
  • scaleOptions: Options for the drop-down box
  • onDocumentLoadError: Function called in case of an error while loading a document.
    • onDocumentLoadError?: (error: Error) => void
  • onDocumentLoadSuccess: Function called when the document is successfully loaded.
    • onDocumentLoadSuccess?: (pdf: pdfjs.PDFDocumentProxy) => void