【发布时间】:2018-12-04 22:19:50
【问题描述】:
我来了
错误错误:在虚拟文件中找不到文件“Roboto-Regular.ttf” 系统
在角度 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';
似乎 vfs_fonts.js 正在加载,因为我将 console.log 添加到此文件并且它可以工作。
我也尝试添加
<script src="./assets/fonts/vfs.js"></script>
但仍然得到同样的错误。 也许有人对此有解决方案?
UPD 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;
已解决。
【问题讨论】:
标签: angular typescript pdfmake