8

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 ?

Community
  • 1
  • 1
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

4 Answers4

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>
bamse
  • 4,243
  • 18
  • 25
  • 1
    @bamse that means the **pdfmake** doesn't work without include `vfs_fonts.js` ? – Mo. Feb 09 '16 at 10:02
  • 1
    @MuhammedAthimannil it does not work without it. The default configuration requires pdfmake.min.js and vfs_fonts.js – bamse Feb 09 '16 at 14:42
1

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'] 
      }
    }
});
Harsh
  • 445
  • 1
  • 5
  • 13
0

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.

Ade MR
  • 51
  • 2
  • 3
0

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.

Baqer Naqvi
  • 6,011
  • 3
  • 50
  • 68