react-pdf-highlighter-plus
  • Export a PDF with annotations embedded.

    Parameters

    • pdfSource: string | Uint8Array | ArrayBuffer

      The source PDF as a URL string, Uint8Array, or ArrayBuffer

    • highlights: ExportableHighlight[]

      Array of highlights to embed in the PDF

    • options: ExportPdfOptions = {}

      Export options for customizing colors and behavior

    Returns Promise<Uint8Array>

    Promise - The modified PDF as bytes

    Example

    const pdfBytes = await exportPdf(pdfUrl, highlights, {
    textHighlightColor: "rgba(255, 255, 0, 0.4)",
    onProgress: (current, total) => console.log(`${current}/${total} pages`)
    });

    // Download the file
    const blob = new Blob([pdfBytes], { type: "application/pdf" });
    const url = URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = url;
    a.download = "annotated.pdf";
    a.click();
    URL.revokeObjectURL(url);