PDFmake: pdfmake.createPdf is not a function

情到浓时终转凉″ 提交于 2021-02-08 13:42:28

问题


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')

回答1:


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;



来源:https://stackoverflow.com/questions/35494376/pdfmake-pdfmake-createpdf-is-not-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!