Skip to content

[WC-3050] Retrieve pdfjs worker locally instead of cdn #1817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/document-viewer-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Changed

- We moved the bundle of pdfjs worker to local build instead of using CDN for better CSP compliance.

## [1.0.0] - 2025-05-05

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import { downloadFile } from "../utils/helpers";
import { useZoomScale } from "../utils/useZoomScale";
import BaseViewer from "./BaseViewer";
import { DocRendererElement, DocumentRendererProps, DocumentStatus } from "./documentRenderer";
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
"/widgets/com/mendix/shared/pdfjs/pdf.worker.mjs",
import.meta.url
).toString();

const options = {
cMapUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/cmaps/`,
standardFontDataUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/standard_fonts`
cMapUrl: "/widgets/com/mendix/shared/pdfjs/cmaps/",
standardFontDataUrl: "/widgets/com/mendix/shared/pdfjs/standard_fonts"
};

const PDFViewer: DocRendererElement = (props: DocumentRendererProps) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/pluggableWidgets/document-viewer-web/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mendix/document-viewer-web",
"widgetName": "DocumentViewer",
"version": "1.0.0",
"version": "1.1.0",
"description": "View PDF and other document types",
"copyright": "© Mendix Technology BV 2025. All rights reserved.",
"license": "Apache-2.0",
Expand Down Expand Up @@ -38,8 +38,8 @@
"@mendix/widget-plugin-component-kit": "workspace:*",
"@mendix/widget-plugin-platform": "workspace:*",
"classnames": "^2.5.1",
"docx-preview": "^0.3.5",
"pdfjs-dist": "^5.0.375",
"docx-preview": "^0.3.6",
"pdfjs-dist": "4.8.69",
"react-pdf": "^9.2.1",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import commonjs from "@rollup/plugin-commonjs";
import replace from "@rollup/plugin-replace";
import copy from "rollup-plugin-copy";
import { copyDefaultFilesPlugin } from "@mendix/rollup-web-widgets/copyFiles.mjs";

export default args => {
Expand Down Expand Up @@ -43,7 +44,26 @@ export default args => {
"!PDFWorkerUtil.isWorkerDisabled && !PDFWorker.#mainThreadWorkerMessageHandler": "false"
}
}),
copyDefaultFilesPlugin()
copyDefaultFilesPlugin(),
copy({
targets: [
{
src: "node_modules/pdfjs-dist/cmaps",
dest: "dist/tmp/widgets/com/mendix/shared/pdfjs/",
flatten: false
},
{
src: "node_modules/pdfjs-dist/standard_fonts",
dest: "dist/tmp/widgets/com/mendix/shared/pdfjs/",
flatten: false
},
{
src: "node_modules/pdfjs-dist/build/pdf.worker.min.mjs",
dest: "dist/tmp/widgets/com/mendix/shared/pdfjs/",
rename: "pdf.worker.mjs"
}
]
})
]
};
});
Expand Down
Loading
Loading