我遇到了问题:
ERROR Error: 文件 'Roboto-Regular.ttf' 在虚拟文件系统中未找到。
当我尝试在 Angular 6 中使用 pdfMake 时。
我已经进行了以下操作:
declare module 'pdfmake/build/pdfmake.js';
declare module 'pdfmake/build/vfs_fonts.js';`
在 typings.d.ts 文件中,同时也
"typeRoots": [
"node_modules/@types",
"../src/typings.d.ts"
],
在tsconfig.json文件中。
在我使用pdfmake的组件中,我有以下代码:
import 'pdfmake/build/vfs_fonts.js';
import * as pdfMake from 'pdfmake/build/pdfmake.js';
看起来是因为我在这个文件中添加了console.log,所以vfs_fonts.js被加载了。
另外我试着只添加了
<script src="./assets/fonts/vfs.js"></script>
但仍然遇到相同的错误。 也许有人有解决方法?
更新1: 在之前导入pdfmake.js并没有解决问题。
import * as pdfMake from 'pdfmake/build/pdfmake.js';
import 'pdfmake/build/vfs_fonts.js';
解决方案:
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
并且
pdfMake.vfs = pdfFonts.pdfMake.vfs;
问题已解决。
( <任何> pdfMake ).vfs = pdfFonts.pdfMake.vfs
。 - NoNam4