Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: include wasm assets in pdf.js-based viewer (#13122)

shamoon71e2dd4b0847
diff --git a/src-ui/angular.json b/src-ui/angular.json
index 391dcc710..dcd5d7e45 100644
--- a/src-ui/angular.json
+++ b/src-ui/angular.json
@@ -79,6 +79,16 @@
"glob": "{pdf.worker.min.mjs,pdf.min.mjs}",
"input": "node_modules/pdfjs-dist/legacy/build/",
"output": "/assets/js/"
+ },
+ {
+ "glob": "**/*",
+ "input": "node_modules/pdfjs-dist/wasm/",
+ "output": "/assets/wasm/"
+ },
+ {
+ "glob": "**/*",
+ "input": "node_modules/pdfjs-dist/iccs/",
+ "output": "/assets/iccs/"
}
],
"styles": [
diff --git a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.ts b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.ts
index 4573e0714..92294154b 100644
--- a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.ts
+++ b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.ts
@@ -61,6 +61,7 @@ describe('PngxPdfViewerComponent', () => {
it('resolves the worker source relative to the document base URI', async () => {
setBaseHref('/paperless/')
+ const getDocumentSpy = jest.spyOn(pdfjs, 'getDocument')
await initComponent()
@@ -70,6 +71,13 @@ describe('PngxPdfViewerComponent', () => {
expect(pdfjs.GlobalWorkerOptions.workerSrc).toContain(
'/paperless/assets/js/pdf.worker.min.mjs'
)
+ expect(getDocumentSpy).toHaveBeenCalledWith({
+ url: 'test.pdf',
+ password: undefined,
+ withCredentials: true,
+ wasmUrl: expect.stringContaining('/paperless/assets/wasm/'),
+ iccUrl: expect.stringContaining('/paperless/assets/iccs/'),
+ })
})
it('initializes single-page viewer and disables text layer', async () => {
diff --git a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.ts b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.ts
index 2bb5273ac..dba57ef2d 100644
--- a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.ts
+++ b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.ts
@@ -174,10 +174,12 @@ export class PngxPdfViewerComponent
'assets/js/pdf.worker.min.mjs',
this.document.baseURI
).toString()
- let initOptions = {
+ const initOptions = {
url: this.src,
password: this.password,
withCredentials: true,
+ wasmUrl: new URL('assets/wasm/', this.document.baseURI).toString(),
+ iccUrl: new URL('assets/iccs/', this.document.baseURI).toString(),
}
this.loadingTask = getDocument(initOptions)
try {