Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

[MISC] Load pdfjs worker from node_modules instead of CDN (#1716)

Chandrasekharan Mab906b3e4254
diff --git a/frontend/src/components/custom-tools/pdf-viewer/PdfViewer.jsx b/frontend/src/components/custom-tools/pdf-viewer/PdfViewer.jsx
index ca81cbba9..58f4cff85 100644
--- a/frontend/src/components/custom-tools/pdf-viewer/PdfViewer.jsx
+++ b/frontend/src/components/custom-tools/pdf-viewer/PdfViewer.jsx
@@ -4,8 +4,10 @@ import { defaultLayoutPlugin } from "@react-pdf-viewer/default-layout";
import { pageNavigationPlugin } from "@react-pdf-viewer/page-navigation";
import PropTypes from "prop-types";
import { highlightPlugin } from "@react-pdf-viewer/highlight";
+
import "@react-pdf-viewer/highlight/lib/styles/index.css";
import "./Highlight.css";
+import { PDF_WORKER_URL } from "../../../helpers/pdfWorkerConfig";
let RenderHighlights;
try {
@@ -97,7 +99,7 @@ function PdfViewer({ fileUrl, highlightData, currentHighlightIndex }) {
return (
<div ref={parentRef} className="doc-manager-body">
- <Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js">
+ <Worker workerUrl={PDF_WORKER_URL}>
<Viewer
fileUrl={fileUrl}
plugins={[
diff --git a/frontend/src/helpers/pdfWorkerConfig.js b/frontend/src/helpers/pdfWorkerConfig.js
new file mode 100644
index 000000000..26e25a720
--- /dev/null
+++ b/frontend/src/helpers/pdfWorkerConfig.js
@@ -0,0 +1,6 @@
+// Webpack 5 / Vite compatible asset module
+// Works with both CRA (Webpack) and Vite bundlers
+export const PDF_WORKER_URL = new URL(
+ "pdfjs-dist/build/pdf.worker.min.js",
+ import.meta.url
+).toString();