最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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 ?

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 ?

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Feb 4, 2015 at 11:47 Abdennour TOUMIAbdennour TOUMI 93.2k42 gold badges267 silver badges269 bronze badges 1
  • 2 Were you able to solve this issue? – Stephen Nielsen Commented May 13, 2015 at 16:47
Add a comment  | 

4 Answers 4

Reset to default 16

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'] 
      }
    }
});

I had the same issue, but including the files using script tags, by the correct order, or with the require JS fix didn't work.

What worked for me was replacing vfs_fonts.js for its latest version from the pdfmake GitHub repository.

I am working in Asp .Net MVC & had the same issue. I was including files in BundleConfig.cs. Then I moved files out from that file and placed those file directly in the view and it worked for me.

发布评论

评论列表(0)

  1. 暂无评论