Angular 文件';pdfmake/build/Roboto Regular.ttf';使用两种语言时在虚拟文件系统中找不到(pdfMake)
我想通过在Ionic/Angular中使用pdfMake生成中英文pdf。我使用gulp创建了一个新的vfs_fonts.js,并替换了Build文件夹中的原始文件,还将所有.ttf文件放在了同一个Build文件夹中。如果我不定义,它可以输出英文(但不能输出中文)Angular 文件';pdfmake/build/Roboto Regular.ttf';使用两种语言时在虚拟文件系统中找不到(pdfMake),angular,ionic-framework,pdfmake,Angular,Ionic Framework,Pdfmake,我想通过在Ionic/Angular中使用pdfMake生成中英文pdf。我使用gulp创建了一个新的vfs_fonts.js,并替换了Build文件夹中的原始文件,还将所有.ttf文件放在了同一个Build文件夹中。如果我不定义,它可以输出英文(但不能输出中文) pdfMake.fonts = { Roboto: { normal: XXXXX .......... }, cwTeXQMing: { normal: XXXXX ...
pdfMake.fonts = {
Roboto: {
normal: XXXXX
..........
},
cwTeXQMing: {
normal: XXXXX
..........
}
};
但一旦我将这些代码放在适当的位置,它将警告我错误“文件'pdfmake/build/Roboto Regular.ttf'未在虚拟文件系统中找到”或“文件'pdfmake/build/cwTeXOMing.ttf'未在虚拟文件系统中找到”。我用谷歌搜索,但这些解决方案似乎对我不起作用。请帮忙
import * as pdfMake from 'pdfmake/build/pdfmake.js'; // Could not find a declaration file for
// module 'pdfmake/build/pdfmake.js'
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;
pdfMake.fonts = {
Roboto: {
normal: 'pdfmake/build/Roboto-Regular.ttf',
bold: 'pdfmake/build/Roboto-Regular.ttf',
italics: 'pdfmake/build/Roboto-Regular.ttf',
bolditalics: 'pdfmake/build/Roboto-Regular.ttf'
},
cwTeXQMing: {
normal: 'pdfmake/build/cwTeXQMingZH-Medium.ttf',
bold: 'pdfmake/build/cwTeXQMingZH-Medium.ttf',
italics: 'pdfmake/build/cwTeXQMingZH-Medium.ttf',
bolditalics: 'pdfmake/build/cwTeXQMingZH-Medium.ttf'
}
};
@Component({
selector: 'app-export',
templateUrl: './export.page.html',
styleUrls: ['./export.page.scss'],
})
export class ExportPage {
selectVersion = '';
pdfObj = null;
constructor() {}
async createPdf() {
if (this.selectVersion === 'Chinese') {
const docDefinition = {
pageSize: 'A4',
font: 'cwTeXQMing',
content: [
{
text: '通知我'
, style: 'firstParagraph'
},
],
defaultStyle: {
font: 'cwTeXQMing',
},
styles: {
font: 'cwTeXQMing',
firstParagraph: {
fontSize: 11,
},
}
};
this.pdfObj = pdfMake.createPdf(docDefinition);
} else { // TO OUTPUT ENGLISH
const docDefinition = {
pageSize: 'A4',
content: [
{
text: 'THIS IS ENGLISH PDF'
, style: 'firstParagraph'
},
],
styles: {
firstParagraph: {
fontSize: 11,
},
}
};
this.pdfObj = pdfMake.createPdf(docDefinition);
}
解决了。与“normal:'pdfmake/build/Roboto Regular.ttf'”不同,只需键入文件名“normal:'Roboto Regular.ttf'。我遇到了类似的问题,我只需更新
vfs\u font.js
的CDN链接即可解决
您可以在以下位置查看链接: