问题描述:

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 ?

网友答案:

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'] 
      }
    }
});
相关阅读:
Top