Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'Roboto-Regular.ttf' of undefined

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

Does Roboto-Regular.ttf File is required ?

And Where to put it ,if so ?

like image 957
Abdennour TOUMI Avatar asked Feb 04 '15 11:02

Abdennour TOUMI


2 Answers

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>
like image 146
bamse Avatar answered Nov 09 '22 05:11

bamse


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'] 
      }
    }
});
like image 1
Harsh Avatar answered Nov 09 '22 04:11

Harsh