I am trying to build a simple custom pdf in LwC using jsPDF v2.5.1 library and loading this library using loadscript in rendered callback method, now I am trying render HTML content in PDF using doc.html in generatePDF method as shown below, but however the HTML content is not rendering.
Below is the js code.
import { LightningElement } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import jsPDF from '@salesforce/resourceUrl/jsPDF';
renderedCallback(){
Promise.all([
loadScript(this, jsPDF)
])
.then(() => {
console.log('jsPDF loaded');
})
.catch(error => {
// Handle error if the library fails to load
console.error('Error loading jsPDF library in catch', error);
});
}
generatePDF(){
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.html("<table><tr><td>Data1</td><td>Data2</td></tr><td>Data3</td><td>Data4</td></tr></table>",{
callback: function(pdf){
pdf.save('');
}
})
}
}
Can someone point out what I am missing here?