We are getting the error "pdflib:17785 Uncaught (in promise) TypeError: fontkit.create is not a function"
What were you trying to do?
We are using the Salesforce LWC components, where using the custom fonts with the download functionality, but we are getting the "pdflib:17785 Uncaught (in promise) TypeError: fontkit.create is not a function" once downloading the custom fonts with the Fontkit library.
Could you please share the correct Fontkit library, so we can use it here.
How did you attempt to do it?
We are using the Salesforce LWC components, where using the custom fonts with the download functionality, but we are getting the "pdflib:17785 Uncaught (in promise) TypeError: fontkit.create is not a function" once downloading the custom fonts with the Fontkit library.
Could you please share the correct Fontkit library, so we can use here.
What actually happened?
We are using below 2 lines to import the static pdfLib and Fontkit library in our salesforce database. import pdflib from "@salesforce/resourceUrl/pdflib"; import fontkit from "@salesforce/resourceUrl/fontkit";
While we ar using the below code, we are getting the error after pdfDoc.embedFont() function. const pdfDoc = await PDFLib.PDFDocument.create(); pdfDoc.registerFontkit(fontkit); const timesRomanFont = await pdfDoc.embedFont( fontBytes );
What did you expect to happen?
It should download the PDF file with the custom fonts
How can we reproduce the issue?
async createPdf() { //const fontkit = pdflib; loadScript(this, fontkit).then(() => { console.log('fontkit loded'); }); console.log('fontkit : '+fontkit); ///LightningMemberPortal/resource/OLDENGL/OldEnglishFive-axyVg.ttf //const url = specFontsOLDENGL+'/OldEnglishFive-axyVg.ttf';
const url = specFonts+'/oldenglishfivefont/OldEnglishFive.ttf';
console.log('url : '+url);
const fontBytes = await fetch(url).then(res => res.arrayBuffer());
console.log('fontBytes : '+fontBytes);
console.log(fontBytes);
const pdfDoc = await PDFLib.PDFDocument.create();
pdfDoc.registerFontkit(fontkit);
debugger;
const timesRomanFont = await pdfDoc.embedFont(
fontBytes
);
const page = pdfDoc.addPage();
const { width, height } = page.getSize();
const fontSize = 30;
page.drawText('View certificate for the AKA', {
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("AKA Certificate", pdfBytes);
}
Version
We are using the latest version of pdf-lib
What environment are you running pdf-lib in?
Other
Checklist
- [X] My report includes a Short, Self Contained, Correct (Compilable) Example.
- [X] I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
No response
I am also getting this issue in Salesforce. Do we have a workaround while we wait for the fix?