我正在使用pdf-kit生成Web到PDF。为此,我通过npm在angular(最新版本)中安装了这些软件包,该软件包使用了一些库,例如“ fs,stream,zlib,..”。
为此,当我运行ng服务时,它显示出许多错误,例如:
Can't resolve 'fs' in '\node_modules\..'
Can't resolve 'stream' in '\node_modules\..'
要绕过这个问题,我在package.json中添加了特定条目。现在, ng服务运行正常,但在浏览器控制台上出现运行时错误:
Uncaught TypeError: Cannot read property 'prototype' of undefined
at __extends (EncodeStream.js:5)
at EncodeStream.js:18
at Object.<anonymous> (EncodeStream.js:147)
at Object../node_modules/restructure/src/EncodeStream.js (EncodeStream.js:151)
at __webpack_require__ (bootstrap:79)
at Object.<anonymous> (index.js:5)
at Object../node_modules/restructure/index.js (index.js:43)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/fontkit/index.js (index.js:5)
at __webpack_require__ (bootstrap:79)
component.ts文件:
import * as pdfkit from 'pdfkit';
import * as blobstream from 'blob-stream';
export class MyComponent implements OnInit {
//Some code..
downloadPDF(){
var doc=new pdfkit();
var stream= doc.pipe(blobstream());
doc.fontSize(25).text('Test PDF !',100,100);
doc.circle(280,200,50).fill("#6600FF");
doc.end();
stream.on('finish', function(){
window.open(stream.toBlobURL('application/pdf'));
});
}
}
非常感谢任何帮助。