react-pdf-highlighter-plus

The props type for PdfLoader.

interface PdfLoaderProps {
    disableAutoFetch?: boolean;
    disableStream?: boolean;
    document: string | DocumentInitParameters | URL | TypedArray;
    enableCache?: boolean;
    httpHeaders?: Record<string, string>;
    rangeChunkSize?: number;
    withCredentials?: boolean;
    workerSrc?: string;
    beforeLoad?(progress): ReactNode;
    children(pdfDocument): ReactNode;
    errorMessage?(error): ReactNode;
    onError?(error): void;
}

Properties

disableAutoFetch?: boolean

Only fetch the pages needed to render, instead of background-downloading the whole file. Makes the first page appear fast for large PDFs served over an API — provided the server supports HTTP range requests (Accept-Ranges: bytes). Has no effect for servers without range support or for raw bytes.

Default

true
disableStream?: boolean

Disable progressive streaming of the response.

Default

false
document: string | DocumentInitParameters | URL | TypedArray

The document to be loaded by PDF.js. If you need to pass HTTP headers, auth parameters, or other pdf settings, do it through here.

enableCache?: boolean

Cache the loaded document so re-opening the same URL (or a StrictMode/ remount) reuses it instead of re-downloading. Only URL-based documents are cached. Disable if the same URL can return different content.

Default

true
httpHeaders?: Record<string, string>

Extra HTTP headers for the document request (e.g. an auth token).

rangeChunkSize?: number

Size (bytes) of each range request when streaming. PDF.js default ~64KB.

withCredentials?: boolean

Send credentials (cookies) with the document request.

workerSrc?: string

Optional PDF.js worker source override. By default, PdfLoader resolves the worker from the installed pdfjs-dist package so bundlers can emit it locally.

Methods

  • Callback to render content before the PDF document is loaded. Receives the PDF.js progress, or null before any progress is known (e.g. a cache hit).

    Parameters

    • progress: null | OnProgressParameters

      PDF.js progress status, or null.

    Returns ReactNode

    • Component to be rendered in space of the PDF document while loading.
  • Child components to use/render the loaded PDF document.

    Parameters

    • pdfDocument: PDFDocumentProxy

      The loaded PDF document.

    Returns ReactNode

    • Component to render once PDF document is loaded.
  • Component to render in the case of any PDF loading errors.

    Parameters

    • error: Error

      PDF loading error.

    Returns ReactNode

    • Component to be rendered in space of the PDF document.
  • Callback triggered whenever an error occurs.

    Parameters

    • error: Error

      PDF Loading error triggering the event.

    Returns void

    • Component to be rendered in space of the PDF document.