Salesforce Asked by Alef Ribeiro on January 2, 2022
I’m creating an lwc component that shows a pdf with canvas, the lib I’m using is this:PDF,js
when trying to load lib, returns me an undefined error, can someone help me how to load correctly
My Html
<template>
<lightning-card>
<div class="container">
<canvas id="the-canvas" class="canvas" lwc:dom="manual"></canvas>
</div>
</lightning-card>
</template>
My Js
import { LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { loadScript } from 'lightning/platformResourceLoader';
import PdfViewerJs from '@salesforce/resourceUrl/pdfViewer';
export default class compC21Body extends LightningElement {
renderedCallback() {
const jsPath = PdfViewerJs + '/pdf.js';
window.console.log(jsPath);
loadScript(this, jsPath).then(() => {
window.console.log('success');
}).catch(error => {
window.console.log(error);
this.dispatchEvent(
new ShowToastEvent({
title: 'Error Pdf Viewer',
message: error ? error.message : 'We get error to load some script :/',
variant: 'error',
}),
);
});
}
}
I put the lib build folder inside the statistic feature in salesforce
Inside the static resource folder we have the files
if you have any library suggestions, I just need it to use canvas and not iframe
error update
SecureElement does not allow access to charset
Failed to load script at /resource/1573759295000/pdfViewer/pdf.js: regeneratorRuntime is not defined [regeneratorRuntime is not defined]
Try uploading just the pdf js file in a separate static resource and pdf worker js in a separate static resource and load pdf js first and worker js next.
import { LightningElement } from 'lwc';
import PDFJS from '@salesforce/resourceUrl/pdfJS';
import PDFWORKER from '@salesforce/resourceUrl/pdfWorker'
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
export default class PdfPoc extends LightningElement {
scale = 1;
connectedCallback(){
Promise.all([loadScript(this, PDFJS), loadScript(this, PDFWORKER )]).then(()=>{
console.log('PDF JS loaded');
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFWORKER;
this.paintCanvas();
}).catch((error)=>{
console.log(' Error loading scripts '+ error);
})
}
Answered by Manjunatha V P on January 2, 2022
0 Asked on November 20, 2020 by jairam
css lightning datatable lightning web components salesforcedx
2 Asked on November 20, 2020 by c0depirate
1 Asked on November 12, 2020 by devforce
1 Asked on November 11, 2020 by crm-guy
2 Asked on November 8, 2020 by johannes-schapdick
1 Asked on November 4, 2020 by the-chinese-filipino
1 Asked on November 4, 2020 by degmo
pre chat service cloud console servicecloud snap ins visualforce
1 Asked on November 3, 2020 by sankhadeep-biswas
1 Asked on October 27, 2020 by chaithra-k-n
0 Asked on October 26, 2020 by vignesh-waran
0 Asked on October 25, 2020
1 Asked on October 11, 2020 by r-rothwell
1 Asked on October 8, 2020 by itai-shmida
1 Asked on October 3, 2020 by nandy
1 Asked on October 3, 2020 by dsk
1 Asked on September 30, 2020 by sfdc-in
1 Asked on September 19, 2020 by naveen-vm
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir