here i am trying to create a pdf in salesforce using pdflib but when i click create pdf i got his error
import { LightningElement } from "lwc";
import PDFLib from "@salesforce/resourceUrl/pdflib";
import { loadScript } from "lightning/platformResourceLoader";
export default class CreatePDF extends LightningElement {
async connectedCallback() {
await loadScript(this, PDFLib).then(() => {
console.log('jsPDF script loaded successfully');
})
.catch(error => {
console.error('Error loading jsPDF library:', error);
});
}
async createPdf() {
console.log('inside generatePDF 19');
const pdfDoc = await PDFLib.PDFDocument.create();
console.log('inside pdf');
const timesRomanFont = await pdfDoc.embedFont(
PDFLib.StandardFonts.TimesRoman
);
const page = pdfDoc.addPage();
const { width, height } = page.getSize();
const fontSize = 30;
page.drawText("Learning with Salesforce Bolt !", {
x: 50,
y: height - 4 * fontSize,
size: fontSize,
font: timesRomanFont,
color: PDFLib.rgb(0, 0.53, 0.71)
});
const pdfBytes = await pdfDoc.save();
this.saveByteArray("My PDF", pdfBytes);
}
saveByteArray(pdfName, byte) {
var blob = new Blob([byte], { type: "application/pdf" });
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
var fileName = pdfName;
link.download = fileName;
link.click();
}
}
createPDF.js:50 Uncaught (in promise) TypeError: Cannot read properties of undefined