PDFmake:pdfmake.createPdf不是一个函数

2024-01-06

安装后pdfmake使用 npm:

npm install pdfmake --save-dev

并编译捆绑包webpack我在运行时遇到错误:

pdfmake = require 'pdfmake'
pdfmake.createPdf(doc_definition).download('test.pdf')

Saying:

pdfmake.createPdf is not a function

我读了this https://stackoverflow.com/questions/27421528/pdfmake-use-in-an-application-with-webpack建议,安装脚本加载器并将要求更改为:

pdfmake = require 'script!pdfmake'

但这带来了更多的错误。此外,我不知道需要什么脚本加载器。有什么建议么?

EDIT如上所述here https://github.com/bpampuch/pdfmake/issues/150看起来好像 NPM 安装了节点(服务器端)版本pdfmake而不是浏览器端版本,两者都有完全不同的 API。这应该是浏览器端的正确流程:

npm install pdfmake --save-dev
pdfmake = require 'pdfmake'
pdfmake.createPdf(doc_definition).download('test.pdf')

在服务器端不支持方法 createPdf。

服务器端 pdfmake Nodejs - TypeError:pdfmake.createPdf 不是函数 #1355 https://github.com/bpampuch/pdfmake/issues/1355

但我尝试过var PDF = require('pdfmake/build/pdfmake')错误消失了。

我还建议你得到vfs_fonts too

var PDF_Fonts=require('pdfmake/build/vfs_fonts')

并设置pdfmake.vfs像这样

PDF.vfs = PDF_Fonts.pdfMake.vfs;

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PDFmake:pdfmake.createPdf不是一个函数 的相关文章

随机推荐