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

@pdf-highlight/react-pdf-highlight

v2.4.0

Published

react pdf highlight keyword

Readme

PDF Highlight => PDFJS version 3.11.174

type Props = {
  url?: string // pdf file path
  width?: number | string // The width specifies the horizontal size for rendering the PDF,
  scale?: number // The scale controls the zoom level of the PDF when rendering, adjusting its size larger or smaller,
  page?: number //The page refers to the specific page of the PDF to render. If not provided, all pages of the PDF will be rendered.
  pageSearch?: number // The pageSearch refers to the specific page of the PDF where the search will be performed. If not provided, the search will be conducted across all pages.,
  onLoaded?: (error?: any) => void, // Called once the pages currently in view are drawn (pages further down render lazily while scrolling). Receives the error when loading or rendering fails.
  onStartLoad?: (error?: any) => void, // Called when a document (re)load or a full re-render starts. Keyword / highlight / replaceTexts changes only repaint the overlay and do not trigger it.
  keywords?: string[] // The keywords parameter is a list (array) of words or phrases that you want to search for within a PDF document. Matching ignores case, whitespace and line breaks, like a browser's Ctrl+F. These keywords are used to locate specific text within the PDF and highlight them based on the options you've configured (e.g., border or background highlighting), The view scrolls to the first match (like a browser's Ctrl+F) when a document loads and whenever the search changes; call `scrollToMatch()` through a ref to scroll again.
  colorHighlight?: string // Highlight color of replaced text, and of keywords unless colorKeyword is set: a solid fill multiplied over the page (the ink stays dark), or a border with isBorderHighlight. Default = "yellow"
  colorKeyword?: string // Highlight color of keyword matches. Default = colorHighlight
  isBorderHighlight?: boolean // is a flag that allows highlighting keywords by drawing a border around them, instead of changing the background color. This can be useful when you want to visually emphasize the keywords without altering the background style, which can be especially useful for readability or design consistency.,
  styleWrap?: CSSProperties // Is a parameter or property that allows customization of the styles applied to the parent wrapper element that contains the canvas rendering the PDF content.,
  debug?: boolean // Logs to the console: the pdf.js used (version, source, worker), load time and page count, each page's render time and canvas size, one line per painted page (matches per keyword, replaced, reflowed) and the scroll target. Errors are printed even without debug when no onLoaded handles them,
  allowHtml?: boolean, // Adds a transparent, selectable text layer over each page so text can be selected and copied. Default = false
  specialWordRemoves?: string[] // Strings ignored when matching keywords and replaceTexts (e.g. ["-"] to match across hyphenated line breaks). Matching already ignores all whitespace and line breaks,
  maxKeywordLength?: number, // Maximum number of characters (whitespace excluded) of each keyword that is matched. Default = 2000
  pdfjs?: any, // Your own pdf.js, e.g. `import * as pdfjs from "pdfjs-dist"`. Without it, a global `pdfjsLib` already on the page is reused, and only otherwise pdf.js 3.11.174 is loaded from cdnjs. If `GlobalWorkerOptions.workerSrc` is not set, the worker of the same version is loaded from jsdelivr.
  replaceTexts?: { search: string; replace: string; color?: string; background?: string; highlight?: boolean }[], // Replaces text on screen: every occurrence of `search` is covered with `background` and `replace` is drawn in `color` (defaults: the page's own paper and ink colors) with the PDF's embedded font, then marked like a keyword match (colorHighlight / isBorderHighlight) unless `highlight: false`. The paragraph is flowed again like edited text (words wrap, justified text stays justified): a longer replacement pushes the following words on, adding lines below the paragraph and moving the rest of the page down when needed; a shorter one pulls them back. `keywords` match the displayed text, i.e. after replacement. Display only — the PDF file itself is not modified, so do not use it for redaction.
};

import { PDFHighlight } from "@pdf-highlight/react-pdf-highlight";

function App() {
  return (
    <PDFHighlight
      onStartLoad={() => {
        console.log("start loading");
      }}
      onLoaded={() => {
        console.log("end loading");
      }}
      keywords={[
        `facilisis odio sed mi.\nCurabitur suscipit. Nullam vel nisi. Etiam semper ipsum ut lectus. Proin aliquam, erat eget\npharetra commodo, eros mi condimentum quam,`,
      ]}
      replaceTexts={[{ search: "Lorem ipsum", replace: "Hello world" }]}
      url="https://pdfobject.com/pdf/sample.pdf"
    />
  );
}

export default App;