Trying to build a PDF using the JS API PdfMake :
<script type="text/javascript" src="/app/js/vfs_fonts.js"></script>
<script type="text/javascript" src="/app/js/pdfmake.min.js"></script>
Then according to this Helloworld , i run :
var docDef={ content: 'This is an sample PDF printed with pdfMake' }
pdfMake.createPdf(docDef).download('optionalName.pdf');
i've got this error :
Uncaught TypeError: Cannot read property 'Roboto-Regular.ttf' of undefined
I solved the problem importing pdfmake before vfs_fonts.
<script type="text/javascript" src="/app/js/pdfmake.min.js"></script>
<script type="text/javascript" src="/app/js/vfs_fonts.js"></script>
I was getting this error with RequireJS. If you are using RequireJS you can solve it by specifying dependency in shim as follow:
require.config({
baseUrl: 'public/bower_components',
waitSeconds: 200,
paths: {
'jquery' : 'jquery/dist/jquery.min',
'bootstrap' : 'bootstrap/dist/js/bootstrap.min',
'pdfmake': '../js/pdfmake',
'vfs_fonts':'../js/vfs_fonts' },
shim: {
bootstrap:{
deps: ['jquery']
},
'vfs_fonts':{
deps: ['pdfmake']
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With