-
Notifications
You must be signed in to change notification settings - Fork 1
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
Trouble upgrading pdfjs #2
Comments
Ok I have just spent way too long on this but here is where I am with it. My patch: diff --git a/package-lock.json b/package-lock.json
index edf98c7..a596505 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
+ "name": "reagent-pdfjs",
"version": "0.0.1",
"dependencies": {
"react": "^17.0.2",
diff --git a/public/index.html b/public/index.html
index 55332af..64c5e22 100644
--- a/public/index.html
+++ b/public/index.html
@@ -3,11 +3,15 @@
<head>
<meta charset="UTF-8">
<title>demo</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.8.335/pdf.min.js" integrity_no="sha512-SG4yH2eYtAR5eK4/VL0bhqOsIb6AZSWAJjHOCmfhcaqTkDviJFoar/VYdG96iY7ouGhKQpAg3CMJ22BrZvhOUA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
+ <script id="pdfjsscript" defer type="module" onload="console.log">
+ import * as pdfjs from "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.189/pdf.min.mjs";
+ window.pdfjs = pdfjs;
+ window.pdfjs.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.189/pdf.worker.mjs";
+ </script>
</head>
<body>
<div id="root"></div>
<script src="/js/main.js"></script>
</body>
-</html>
\ No newline at end of file
+</html>
diff --git a/src/main/demo/app.cljs b/src/main/demo/app.cljs
index 54832fe..8dedd8f 100644
--- a/src/main/demo/app.cljs
+++ b/src/main/demo/app.cljs
@@ -12,9 +12,7 @@
;; included via script tag in public/index.html
;; it provides the window['pdfjs-dist/build/pdf'] global variable
-(def ^js pdfjs (gobj/get js/window "pdfjs-dist/build/pdf"))
-
-(defn pdf-canvas [{:keys [url]}]
+(defn pdf-canvas [{:keys [url pdfjs]}]
;; ref
(let [canvas-ref (react/useRef nil)]
@@ -57,17 +55,20 @@
[:canvas {:ref canvas-ref}]))
(defn app []
- [:f> pdf-canvas {:url "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf"}])
+ [:f> pdf-canvas {:url "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf"
+ :pdfjs pdfjs}])
(def root-el
(js/document.getElementById "root"))
(defn ^:dev/after-load start []
- (rdom/render [app] root-el))
-
-(defn init []
+ (def ^js pdfjs (gobj/get js/window "pdfjs"))
;; need to tell the lib where to load the worker from, also using same CDN
- (set! (.. pdfjs -GlobalWorkerOptions -workerSrc) "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.8.335/pdf.worker.min.js")
+ #_(set!
+ (.. pdfjs -GlobalWorkerOptions -workerSrc)
+ "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.189/pdf.worker.mjs")
+ (rdom/render [app] root-el))
- (start))
+(defn init []
+ (.addEventListener js/document "DOMContentLoaded" start)) As you see, I put "defer" on the script tag, and waited for DOMContentLoaded before running
That's in the browser console and the trace points to
I have yet to determine what this does to functionality but the network tab confirms that the worker file does get successfully retrieved. |
Seems to be mozilla/pdf.js#17265 |
I updated the example to use the CDN ESM variant. Your approach wasn't ideal. Getting the same MIME type error as you, but seems to work regardless. |
Following your approach, I'd hoped to upgrade pdfjs by changing
reagent-pdfjs/public/index.html
Line 6 in c9ff5cc
to
but if I don't put
type="module"
in the script tag the file won't load—I getUncaught SyntaxError: Unexpected identifier 'r' (at pdf.min.mjs:21:283861)
.If I do put
type="module"
in the script tag, I get the following;I am not sure what to do about this, as in both cases,
window.pdfjsLib
is defined, at least in the browser console, and has a 'GlobalWorkerOptions' prop.The text was updated successfully, but these errors were encountered: