An open API service indexing awesome lists of open source software.

https://github.com/lukasmoellerch/pdf-viewport

A library that makes using pdfjs in react projects easy.
https://github.com/lukasmoellerch/pdf-viewport

pdf pdfjs react reactjs

Last synced: 25 days ago
JSON representation

A library that makes using pdfjs in react projects easy.

Awesome Lists containing this project

README

        


pdf-viewport




A library that makes using pdfjs in react projects easy.






Demo: pdf-viewport.lukas-moeller.ch

# Getting Started

Add `pdfjs-dist` and `pdf-viewport` as dependencies:
```bash
$ yarn add pdfjs-dist pdf-viewport
$ npm install --save pdfjs-dist pdf-viewport
```

Set `pdfjsLib.GlobalWorkerOptions.workerSrc`. You could for example use a hosted variant of the worker or use `worker-loader` to bundle the worker yourself using webpack.
```ts
import * as pdfjsLib from "pdfjs-dist/es5/build/pdf";
pdfjsLib.GlobalWorkerOptions.workerSrc = "[your worker url]"
```

Load the PDF using `getDocument` from pdfjs. You can do this e.g. using `useEffect` or react-query:
```ts
const [pdf, setPdf] = React.useState();
React.useEffect(() => {
getDocument(examplePdf).promise.then(setPdf);
}, []);
```

Now you can use `pdf-viewport` to render the PDF using one of its components:
```tsx

```

## Reference

Coming soon!