0

i have a component lightning and i import 2 scripts "PDF.js" and "scripts.js" my static resource have 3 files zip "PDF.js", "script.js" and "worker.js"

<aura:component >
    <ltng:require scripts="{!$Resource.pdf + '/pdf.js'}"/>
    <ltng:require scripts="{!$Resource.pdf + '/script.js'}"/>

    <input id="inputFile" type="file" onchange="convertToBase64();" />    

    <div id="data"></div>   
</aura:component>

in my script.js static resource i call my worker.js

pdfjsLib.workerSrc = 'worker.js';

but i have a error

Uncaught ReferenceError: pdfjsLib is not defined throws at https://componentstudy-dev-ed.lightning.force.com/resource/1579614876000/olianiTrailhead__pdf/script.js:1:1 ReferenceError: pdfjsLib is not defined
    at script.js:1

can someone help me?

0

You'll need to choose a different library. Aside from possible timing issues regarding the load order for scripts, you cannot use Workers of any type in Lightning because of the Locker API.

5
  • I understand your point but this lib is not for generating PDF but reading and generating readable text from a PDF – Guilherme Feb 4 '20 at 20:10
  • @Guilherme The other half of my answer is still a concern, then... Locker API won't let you have a service worker. – sfdcfox Feb 4 '20 at 20:14
  • @Guilherme Did you check the Developer Console for errors? I'm pretty sure you should see something about an unsupported API or some such in the logs. – sfdcfox Feb 4 '20 at 20:14
  • on my developer console, I have no error, but only on the browser console – Guilherme Feb 4 '20 at 20:20
  • about the locker service, I had this problem, but solved it by downgrade the component version and now i have this error i post – Guilherme Feb 4 '20 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.