I want to add annotation/Highlight Feature on selected text on pdf using react-pdf-viewer permanently. there may be one or more pdf on website and pdf may contain one or more pages.
import React, { useState, useEffect } from "react";
import { Worker, Viewer } from "@react-pdf-viewer/core";
import { ExcelRenderer, OutTable } from "react-excel-renderer";
import { defaultLayoutPlugin } from "@react-pdf-viewer/default-layout";
import "@react-pdf-viewer/highlight/lib/styles/index.css";
import "@react-pdf-viewer/core/lib/styles/index.css";
import "@react-pdf-viewer/default-layout/lib/styles/index.css";
import { highlightPlugin, Trigger } from "@react-pdf-viewer/highlight";
import "@react-pdf-viewer/highlight/lib/styles/index.css";
import { backendBaseUrl } from "../config";
function DocumentDrawer({ isOpen, toggle, viewFile }) {
const newPdfPlugin = defaultLayoutPlugin();
const [fileType, setFileType] = useState(null);
const [excelData, setExcelData] = useState(null);
const highlightPluginInstance = highlightPlugin();
return (
<div className={sidebar_content_viewer ${isOpen ? "open" : ""}}>
<button className="btn ms-5 btn-primary close-button" onClick={toggle}>
Close
</button>
<div className="slider_inner_contentview">
<div className="file_container">
{fileType === "pdf" && (
<Worker workerUrl="https://unpkg.com/pdfjs-dist@3.11.174/build/pdf.worker.min.js">
<Viewer
fileUrl={${backendBaseUrl}/api/documents/ + viewFile}
plugins={[newPdfPlugin, highlightPluginInstance]}
defaultScale={1.2}
preload={true}
/>
</Worker>
)}
</div>
</div>
</div>
);
}
export default DocumentDrawer;