MCPcopy Index your code
hub / github.com/agentcooper/react-pdf-highlighter

github.com/agentcooper/react-pdf-highlighter @v4.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.0.0 ↗ · + Follow
79 symbols 152 edges 33 files 0 documented · 0% 3 cross-repo links updated 19mo ago★ 1,39836 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

☕️ Buy me a coffee

Node CI

react-pdf-highlighter

react-pdf-highlighter is a React library that provides annotation experience for PDF documents on web. It is built on top of PDF.js by Mozilla. Text and rectangular highlights are supported. Highlight data format is independent of the viewport, making it suitable for saving on the server.

Example (Create React App)

For online example check https://agentcooper.github.io/react-pdf-highlighter/.

To run the example app locally:

npm install
npm start

While docs are in progress, feel free to check the source annotated with Flow type signatures.

Installation

npm install react-pdf-highlighter

See packages/example/src/App.js for React component API example.

Prior art

react-pdf and react-pdfjs only provide React wrappers for PDF.js and do not have built-in annotation functionality.

pdfjs-annotate does not provide text highlights out of the box.

PDF.js provides only viewer:

PDF.js is mainly written for reading PDF files, not editing them. Because of that we don't yet support adding any kind of annotations. We do however support rendering a number of annotation types for viewing.

See also:

  • https://github.com/mozilla/pdf.js
  • https://github.com/wojtekmaj/react-pdf
  • https://github.com/erikras/react-pdfjs
  • https://github.com/instructure/pdf-annotate.js/
  • https://blogs.dropbox.com/tech/2016/11/annotations-on-document-previews/

FAQ

Can I get a new PDF with the highlights embedded into the document?

No, but pdf-annotation-service might be helpful for you.

Wasn't this named react-pdf-annotator at some point?

Yes, but people from https://www.pdfannotator.com/ asked me to rename, since they have a trademark for PDF Annotator.

I'm trying the demo with my PDF and it is not loading!

Please check the CORS headers on your url. It is required for the cross-domain request.

Compatibility

Works in Google Chrome, Safari 10+, Firefox 52+. Not tested in Internet Explorer.

Contributing

To publish a new version:

npx lerna version

cd ./packages/react-pdf-highlighter
npm publish

PDF.js worker thread

The default worker is an inline "fake" worker. To improve performance, either add the worker-loader (preferred) to your webpack config or use the inline loader syntax.

Webpack config example snippet

Use this if have your own config

{
  ...
  module: {
    rules: [
      {
        test: /\.worker\.js$/,
        use: 'worker-loader',
      },
      ...
    ]
  }
}

Inline Webpack-loader syntax

Use in Create React App projects

import PDFWorker from "worker-loader!pdfjs-dist/lib/pdf.worker";

import {setPdfWorker} from 'react-pdf-highlighter';

setPdfWorker(PDFWorker);
...

Core symbols most depended-on inside this repo

asElement
called by 8
packages/react-pdf-highlighter/src/lib/pdfjs-dom.js
isHTMLElement
called by 7
packages/react-pdf-highlighter/src/lib/pdfjs-dom.js
viewportToScaled
called by 4
packages/react-pdf-highlighter/src/lib/coordinates.js
containerCoords
called by 3
packages/react-pdf-highlighter/src/components/MouseSelection.js
getDocument
called by 3
packages/react-pdf-highlighter/src/lib/pdfjs-dom.js
getWindow
called by 3
packages/react-pdf-highlighter/src/lib/pdfjs-dom.js
scaledToViewport
called by 3
packages/react-pdf-highlighter/src/lib/coordinates.js
setPdfWorker
called by 2
packages/react-pdf-highlighter/src/components/PdfLoader.js

Shape

Function 55
Class 13
Method 11

Languages

TypeScript100%

Modules by API surface

packages/react-pdf-highlighter/src/components/PdfHighlighter.js15 symbols
packages/react-pdf-highlighter/src/components/PdfLoader.js10 symbols
packages/example/src/App.js9 symbols
packages/react-pdf-highlighter/src/lib/pdfjs-dom.js8 symbols
packages/react-pdf-highlighter/src/lib/optimize-client-rects.js7 symbols
packages/react-pdf-highlighter/src/components/MouseSelection.js7 symbols
packages/react-pdf-highlighter/src/components/TipContainer.js6 symbols
packages/react-pdf-highlighter/src/lib/coordinates.js3 symbols
packages/react-pdf-highlighter/src/components/MouseMonitor.js3 symbols
packages/react-pdf-highlighter/src/components/Tip.js2 symbols
packages/example/tests/integration.test.js2 symbols
packages/react-pdf-highlighter/src/lib/get-client-rects.js1 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add react-pdf-highlighter \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page