New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pdfjs-react-frame

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfjs-react-frame

This is a wrapper for using Mozilla's PDF.js in a React component. https://github.com/mozilla/pdf.js/

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Overview

This is a wrapper for using Mozilla's PDF.js in a React component. https://github.com/mozilla/pdf.js/

There are a few other examples out there ( this one was particularly useful: https://github.com/seges/react-pdfjs-example )

This builds on those by adding a few abilities:

  1. The text layer - for selectable/searchable text
  2. The ability to scroll to a specific page (or to determine which page the user has already scrolled to)

Usage

import PdfJsFrame from 'pdfjs-react-frame';

<PdfJsFrame
	style={/* optional style object */}
	url={/* URL of a document to fetch - this is required if data is null */}
	data={/* A document to display as an arrayBuffer - this is required if URL is null */}
	pageNumber={/* The page to scroll to (default: 1) */}
	onPageChange={/* optional function to handle page changes, (pageNumber) => { } */}
	workerPath=/* optional (default: Mozilla GitHub) path to serve the worker file locally '/pdf.worker.min.js' */
	loadingElement={/* optional, e.g. <CircularProgress/> */}
/>

https://developer.mozilla.org/en-US/docs/Web/API/Body/arrayBuffer


Serve Worker.js Locally

This is a bit of a hold-over from the fact that the library isn't really designed for React. I couldn't think of a better way to do this without a fairly big rewrite to PDF.js...

In order to use this, you'll also need to ensure that the file is available and served from your application, e.g. by adding this to your package.json

"postinstall": "echo D|xcopy node_modules\\pdfjs-dist\\build\\pdf.worker.min.js public /sy"

FAQs

Package last updated on 21 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc