Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We are getting the error "pdflib:17785 Uncaught (in promise) TypeError: fontkit.create is not a function" #1544

Open
2 tasks done
kauravmayur opened this issue Nov 10, 2023 · 1 comment

Comments

@kauravmayur
Copy link

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

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

@marsh-mellow
Copy link

I am also getting this issue in Salesforce. Do we have a workaround while we wait for the fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants