After referring some articles and answers, I am able to load the pdfmake library from CDN.
We can do this using two ways.
1. Initially Loading : add script tag in the <head>
section of index.html
. And access the global library object exported in the window object.
For PDFMake I have added below scripts in head section,
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.59/pdfmake.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.59/vfs_fonts.js'></script>
and to use it in component declare it on top of component as declare let pdfMake: any ;
use this variable to access pdfmake methods: pdfMake.createPdf(docDefinition)
2. Dynamically Loading : If you want to load library on particular action or in particular component, you add script tag dynamically.
Refer this answer for this approach.
I have written article Loading External Libraries from CDN in Angular on both this approach.