Cannot use downloaded library (pdfmake) offline

Viewed 364

I am trying to use pdfmake JS library in an offline webpage. I downloaded the CDN file from https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/pdfmake.min.js and saved it offline in ..app/js/pdfmake.js

I loaded the library using require:

require([
   'js/pdfmake.js',
...])

I test the library using the example below:

var buttonTS = document.getElementById("buttonTS")
butonTS.addEventListener("click", function(){
            
  var docDefinition = {
    content: [
            'First paragraph',
            'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
        ]
    };

    var now = new Date();

    var pdf = pdfmake.createPdf(docDefinition);
    pdf.write('pdfs/basics.pdf').then(() => {
        console.log(new Date() - now);
    }, err => {
        console.error(err);
    });
}

But the library does not load, and throws the error:

Uncaught ReferenceError: pdfmake is not defined

This is odd because I have other libraries (SweetAlert), which work with no problems.

Thanks for any help!

0 Answers
Related