npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-pdf-highlight

v1.0.0

Published

Set of React components for PDF annotation

Downloads

9

Readme

react-pdf-highlight

react-pdf-highlight is a React library that provides a highly customisable annotation experience for PDF documents on the web, with text and rectangular highlights both supported. It leverages PDF.js as its viewer. The highlight data format is also independent of the viewport, making it suitable for saving on a server.

This originally started as a fork of react-pdf-highlighter but so much has been refactored and redesigned that it would be a burden to pull it to the original repo.

Some of the changes include: PdfViewer, Highlighter, usePdfViewer, useHighlight, and HighlightLayer were added;

Some components are removed , inclides Tip, Popup, MouseMonitor

Efforts will be made to try to ensure feature parity with the original repo, but there are no guarantees that syntax and usage will be the same.

Set of React components for PDF annotation.

Features:

  • Built on top of PDF.js
  • Text and image highlights
  • Popover text for highlights
  • Scroll to highlights

Example

import { PdfViewer, PdfLoader } from "react-pdf-highlight";
import {
  Highlighter,
  HighlightLayer,
  type Highlights,
  type IHighlight,
  useHighlight,
  useLayer,
} from "react-pdf-highlight";
import "pdfjs-dist/web/pdf_viewer.css";
function App() {
  const highlights: Highlights = [];
  const pdfUrl: string = "/path/to/some.pdf";

  const selectionColor = ({ isScrollTo }) => {
    !isScrollTo ? "#fce897" : "#ff6467";
  };

  const highlighterRef = useRef();
  const scrollTo = (hightlight: any) => {
    highlighterRef.current.scrollTo(hightlight);
  };


  return (
    <PdfLoader url={pdfUrl}>
      <PdfViewer>
        <Highlighter
          ref={highlighterRef}
          highlights={highlights}
          enableAreaSelection={(event) => event.altKey}
          {/* *:selection{ background-color: ${selectionColor}}  */}
          cssSelectionColor={selectionColor}
          layerBackgroundColor={"#fce897"} // default
          layerScrolledToBackgroundColor={"#ff6467"} //default
          {/* renderHighlightLayer={  ()=> <HighlightLayer/>} */}
          renderHighlightLayer={() => <CustomHighlightLayer />}
        >
          <HighlightEditor />
        </Highlighter>
      </PdfViewer>
    </PdfLoader>
  );
}

function CustomHighlightLayer() {
  const { highlight, index, pageNumber, onMouseOver, backgroundColor } =
    useLayer();
  //  your own component codes
    return null
}

function HighlightEditor() {
  const { onShow, onHide, highlight } = useHighlight()!;

  const [comment, setComment] = useState<Comment>(
    highlight?.comment ?? { text: "" }
  );
  const [editing, setEditting] = useState(false);
  const onDelete = () => {};
  const onAdd = () => {
    onShow();
    setEditting(true);
  };

  const onEdit = () => {
    setComment(comment);
    setEditting(true);
  };

  const onUpdate = () => {
    onHide();
    // your logic to create/update highlight
  };

  const onCancel = () => onHide();
  const onChangeText = (event) => setComment({ text: event.target.value });

  if (!editing) {
    // new
    if (!highlight?.id) return <button onClick={onAdd}>Add</button>;
    return (
      <div>
        <blockquote>{comment?.text || "No Comment"}</blockquote>
        <div>
          <button onClick={onEdit}>Edit</button>
          <button onClick={onDelete}>Delete</button>
        </div>
      </div>
    );
  }

  return (
    <div>
      <textarea value={comment.text} onChange={onChangeText} />
      <div>
        <button onClick={onSave}>Save</button>
        <button onClick={onCancel}>Cancel</button>
      </div>
    </div>
  );
}

To run the example app locally:

npm install
npm start

Install

npm install react-pdf-highlight

How to use

See ./example/src/App.tsx for the React component API example.

See demo.