After installing pdfmake
using npm:
npm install pdfmake --save-dev
and compiling bundles with webpack
I get an error when running:
pdfmake = require 'pdfmake'
pdfmake.createPdf(doc_definition).download('test.pdf')
Saying:
pdfmake.createPdf is not a function
I've read this suggestion, installed the script-loader and changed the requirement to:
pdfmake = require 'script!pdfmake'
But that gave even more errors. Besides, I wouldn't know what that script loader would be needed. Any suggestions?
EDIT
As described here it seems as if NPM installs the node (serverside) version of pdfmake
instead of the browserside version, both of which have completely different API's. This should be the correct flow for the browserside:
npm install pdfmake --save-dev
pdfmake = require 'pdfmake'
pdfmake.createPdf(doc_definition).download('test.pdf')
On server side method createPdf is not supported.
Server side pdfmake Nodejs - TypeError: pdfmake.createPdf is not a function #1355
BUT I tried var PDF = require('pdfmake/build/pdfmake')
and the error is gone.
Also I suggest you to get the vfs_fonts
too
var PDF_Fonts=require('pdfmake/build/vfs_fonts')
and set the pdfmake.vfs
like this
PDF.vfs = PDF_Fonts.pdfMake.vfs;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With