#Integrating issue about pdfjs's pdf_viewer into Electron

33 messages · Page 1 of 1 (latest)

old sand
#

‌‌Hello everyone, has anyone here tried integrating pdfjs into Electron? I'm running into an issue with pdf_viewer.mjs.

Uncaught TypeError: Cannot read properties of undefined (reading '_on')

Below is my renderer.js source code.

import { getDocument, GlobalWorkerOptions } from './node_modules/pdfjs-dist/build/pdf.mjs';
import { PDFViewer } from './node_modules/pdfjs-dist/web/pdf_viewer.mjs';

GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker.min.mjs';

document.addEventListener('DOMContentLoaded', () => {
  const container = document.getElementById('viewerContainer');
  if (!container) {
    console.error("The container div does not exist!");
    return;
  }

  const viewer = new PDFViewer({
    container: container,
    l10n: { getLanguage: () => Promise.resolve('en'), getDirection: () => 'ltr' }
  });

  const url = 'one_man_view_of_the_world.pdf';

  getDocument(url).promise.then((pdfDoc) => {
    viewer.setDocument(pdfDoc);
  }).catch((error) => {
    console.error('Error loading PDF: ', error);
  });
});
last sierra
#

On what line do you get this error? There is no _on in this code

old sand
#

const viewer = new PDFViewer({
this line

#

‌‌‌‌I tried using gpt4 to help solve it, but it doesn't seem to work well. It keeps prompting this issue.

last sierra
#

You will need to read the source code so you can understand what the problem might be

#

Ah, you have not even searching on GitHub before asking :/

old sand
#

‌‌‌‌‌This is the HTML content from my demo.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>PDF Viewer</title>
    <link rel="stylesheet" href="node_modules/pdfjs-dist/web/pdf_viewer.css" />
  </head>
  <body>
    <div id="viewerContainer" style="width: 100%; height: 100vh;position: absolute;">
      <div></div>
    </div>
    <script type="module" src="renderer.js"></script>
  </body>
</html>

<div></div>It's a method that someone mentioned to me in relation to querying GitHub, which circumvents another issue.

last sierra
#

stop using GPT, try to search yourself first

#

took me 2sec to find

old sand
#

‌‌‌‌‌‌I sincerely apologize. Yesterday, I attempted to inquire through GitHub, but apparently, the keywords I used were not accuracy., leading to a different issue altogether.

last sierra
#

It's okay

old sand
#

‌‌‌‌‌‌‌I'll go and try first. thanks for help.

last sierra
#

I didn't want to sound too harsh 😅

old sand
#

‌hahaha no no no you're right

#

‌‌I often say the same to others. One should look it up before asking, as it saves both of our times.

last sierra
#

Hopefully this issue will solve your problem 🙂

old sand
#

‌‌‌Thank you very much🙏. I followed the example suggested in that issue and fixed the problem. I hope you have a great day.

last sierra
#

Thank you, you too!

old sand
#

I'm a bit curious. It's strange that yesterday I tried searching for the error message on Google several times, incorporating the keywords pdf.js and 'Cannot read properties of undefined (reading '_on')', the latter of which I put in quotes for an exact match, but just now I couldn't replicate the search results you mentioned unless I searched for the issue directly within GitHub's repository search.

last sierra
#

I searched directly on the repo, on all issues (not only the opened ones) and with the keywork "_on"

old sand
#

It seems that I need to improve my search method. I used to rely heavily on Google Search and then refer to the corresponding issues. I haven't really used your method before, and I didn't think that the difference in search methods would lead to such different results. This is really helpful. Thanks a lot. Haha.

last sierra
#

When an issue if very specific to a library, I figured it's usually better to search on the repo first, since Google will return lot of unrelated things

old sand
#

‌‌‌‌Indeed. Thank you for the reminder, I have learned an important lesson.👍

last sierra
#

Glad I could help, ah ah

old sand
last sierra
#

I could have been more tactful

old sand
#

‌‌‌‌‌‌Apart from the search tips you just mentioned, you also gave me a lesson on communication skills. Thank you very much.

last sierra
#

Hmm, I'm not sure I'm a good example when it comes to communication ¯_(ツ)_/¯
Unless you're being ironic?

old sand
#

I mean it sincerely. Having reflected on how I communicate with friends, I realize that my previous approach, though often stating the truth, could be off-putting. Your subsequent comment, 'didn't want to sound too harsh', made me feel much warmer, and I realize that adding such a consideration to my own intentions could make a big difference. I want to help them, and now I understand that the way I go about it could be improved.

#

I wish to construct a note-taking tool based on electron and pdf.js to aid non-native English speakers like myself in reading English PDFs (it could also assist with other languages). Combining Anki would help with memorizing new words encountered. I desire to make this world a better place, even if it's just a little, with my small utility.

last sierra
#

It's very altruistic of you 🙂

old sand
#

‌‌‌‌‌‌‌You also spent your precious time helping me, a complete stranger. Thank you very much. I have to go back to work on my little tools. Hahaha, goodbye.