ansu5555 / pdf-viewer-reactjs

A simple PDF viewer for React js
https://ansu5555.github.io/pdf-viewer-reactjs/
MIT License
140 stars 65 forks source link
document pages pdf pdf-viewer react react-pdf react-pdf-viewer reactjs rotate rotate-pdf zoom zoom-pdf

pdf-viewer-reactjs

GitHub Repo stars

npm npm npm bundle size NPM

Codacy Badge Total alerts codecov GiHub CI workflow

Simple react PDF Viewer component with controls like

Every element can be styled upon your preferences using default classes your own and also custom react element can be passed.

Initially it was forked from mgr-pdf-viewer-react

Hit the :star: on GitHub if you like it

Example: Live demo is available here

How to install


npm i pdf-viewer-reactjs

Note:

Due to causing broken CSS issue bulma & material-design-icons are removed from dependencies and code as well and added as peerDependencies.

Please install bulma & material-design-icons from npm by yourself

npm i bulma material-design-icons

then import them in your CSS as below

@import url('bulma/css/bulma.css');
@import url('material-design-icons/iconfont/material-icons.css');

Else provide custom CSS styles as per your requirement

How to use

import React from 'react'

import PDFViewer from 'pdf-viewer-reactjs'

const ExamplePDFViewer = () => {
  return (
    <PDFViewer
      document={{
        url: 'https://arxiv.org/pdf/quant-ph/0410100.pdf',
      }}
    />
  )
}

export default ExamplePDFViewer

Documentation

React component prop. types:

document:

PropTypes.shape({
  url: String, // URL to the pdf

  base64: String, // PDF file encoded in base64
})

password:

withCredentials:

externalInput:

page:

scale:

rotationAngle:

scaleStep:

minScale:

maxScale:

onDocumentClick:

onPrevBtnClick:

onNextBtnClick:

onZoom:

onRotation:

getMaxPageCount:

css:

canvasCss:

navbarOnTop:

hideNavbar:

hideZoom:

hideRotation:

loader:

alert:

showThumbnail:

PropTypes.shape({
  scale: PropTypes.number, // Thumbnail scale, ranges from 1 to 5

  rotationAngle: PropTypes.number, // Thumbnail rotation angle, values can be -90, 0 or 90. Default is 0

  onTop: PropTypes.bool, // Thumbnail position, if set to true thumbnail will be placed on top

  backgroundColor: PropTypes.string, // Color(hex or rgb) of the thumbnail container

  thumbCss: PropTypes.string, // Custom css class for thumbnails

  selectedThumbCss: PropTypes.string, // Custom css class for selected thumbnail
})

protectContent:

watermark:

PropTypes.shape({
  text: PropTypes.string, // Watermark text

  diagonal: PropTypes.bool, // Watermark placement true for Diagonal, false for Horizontal

  opacity: PropTypes.string, // Watermark opacity, ranges from 0 to 1

  font: PropTypes.string, // custom font name default is 'Comic Sans MS'

  size: PropTypes.string, // Font Size of Watermark

  color: PropTypes.string, // Color(hex or rgb) of the watermark
})

navigation:


PropTypes.oneOfType([

// Can be an object with css classes or react elements to be rendered

PropTypes.shape({

css:  PropTypes.shape({

navbarWrapper:  String, // CSS Class for the Navbar Wrapper

zoomOutBtn:  String, // CSS Class for the ZoomOut Button

resetZoomBtn:  String, // CSS Class for the Reset Zoom Button

zoomInBtn:  String, // CSS Class for the ZoomIn Button

previousPageBtn:  String, // CSS Class for the Previous Page button

pageIndicator:  String, // CSS Class for the Page Indicator

nextPageBtn:  String, // CSS Class for the Next Page button

rotateLeftBtn:  String, // CSS Class for the RotateLeft button

resetRotationBtn:  String, // CSS Class for the Reset Rotation button

rotateRightBtn:  String  // CSS Class for the RotateRight button

})

// Or a full navigation component

PropTypes.any  // Full navigation React element

]);

Author

Image of Author

Ansuman Ghosh

ansu5555.com