How to use external library on angular-cli? (pdfmake)

Viewed 4041

Ok, so, im using angular-cli for my test project and since im new to web development world im trying new thinks. This time I couldn't make it work.

Well, what I tried?

well I kind followed pdfmake readme and into my index.html I placed this two lines inside body tag:

<script src='build/pdfmake.min.js'></script>
<script src='build/vfs_fonts.js'></script>

well, Im getting this error:

GET http://localhost:4200/build/pdfmake.min.js GET http://localhost:4200/build/vfs_fonts.js 404 (Not Found)

So, I took than away, and into my component I only imported pdfmake, like this:

import * as pdfmake from 'pdfmake/build/pdfmake.js';

and what it does? well, nothing, i still didn't called it any where in my code, doing now:

pdfmake.createPdf(this.docDefinition).download();

docDefinition stands for my pdf content.

ok, and now? This error appears:

ERROR Error: File 'Roboto-Regular.ttf' not found in virtual file system

ok, I probably need to import vfs_font, where? well, I have no idea, i tried importing in angular-cli.json at scripts tag, nope, dont work, I even tried importing at my component, nope.

I tried using ng-pdf-make library found ant npm site, well it doesn't work at all.

Im probably making an novice mistake, sorry if its something easy and dumb :P.

@Edit

I tried the same thing he did, and in fact it works with jquery in my project, but it doesn't work for pdfmake.

This is my angular-cli.json script tag:

"scripts": [
        "../node_modules/pdfmake/build/pdfmake.min.js",
        "../node_modules/pdfmake/build/vfs_fonts.js",
        "../node_modules/jquery/dist/jquery.js",
        "../node_modules/tether/dist/js/tether.js",
        "../node_modules/bootstrap/dist/js/bootstrap.js"
      ],

and there is the fact that I cant use pdfmake.createPdf("content") even with the vfs_fonts import:

import * as pdfmake from 'pdfmake/build/pdfmake.min.js';
import * as pdfFonts from 'pdfmake/build/vfs_fonts.js';
2 Answers
Related