Code Monkey home page Code Monkey logo

webviewer-react's Introduction

WebViewer-React

A React component for displaying documents in your React app. It is developed with PDFTron's WebViewer library & React context APIs.

Live Demo

Codesandbox link to be updated

Run the demo locally

To run the demo with context hooks

npm run startctx

To run the demo with <DocumentViewer /> component:

npm run startdv

The above commands will automatically build the component and store the compiled module inside lib/ folder, from where the example app will make imports for components / context hooks. After running the command you will be able to see the app running on http://127.0.0.1:8000.

To use this library in your own project

(package to be published to registry)

npm i @pdftron/webviewer-react

You will need to copy the library assets from './node_modules/@pdftron/webviewer/public' and place them to a location where you are able to serve them. Then provide the URL of the assets to the libLocation prop below. (Check the local demo to get a better understanding of this setup.) Then inside you app's root component (where you setup all other providers):

import { DocumentViewerProvider }
...
  return (
    <DocumentViewerProvider libLocation={url}>
      <ComponentChildren />
    </DocumentViewerProvider>
  )

Now you will be able to use the context hook to add new / acess existing document instances in your React components. Each "instance" represents an element on the page where you want to display the document.

import useInstances from '@pdftron/webviewer-react'
...
const { instances, addInstance } = useInstances()
...
// Note that addInstance is asynchronous
await addInstance(initialDoc, UID, HTMLElement)

Or simply import the component and place it at the places where you want to display your documents.

import { DocumentViewer } from '@pdftron/webviewer-react'
...
  return (
      <ParentComponent>
        <DocumentViewer docUrl={docUrl1} UID={UID1}/>
        <DocumentViewer docUrl={docUrl2} UID={UID2}/>
      </ParentComponent>
  )

Installation for local development of this library

git clone https://github.com/PDFTron/webviewer-react.git
cd webviewer-react
npm install
npm run preparevwlib

Build

Run npm run build to build the project. The compiled module will be stored in the lib directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.