【发布时间】:2017-04-01 02:22:28
【问题描述】:
我正在使用 pdfmake 在客户端创建 PDF。我们有一个所见即所得的编辑器,允许用户创建一个 pdf。然后将其解析为与 pdfmake 一起使用。
但是,我无法使用普通字体。该插件使用vfs_fonts.js在PDF上创建字体,默认为Roboto。
我正在尝试让它与 Times New Roman 等类似的作品一起使用。
我曾尝试像这样更改文件:
window.pdfMake = window.pdfMake || {};
window.pdfMake.vfs = {
Roboto: {
"Roboto-Italic.ttf": "BASE 64 HERE",
"Roboto-Medium.ttf": "BASE 64 HERE",
"Roboto-Regular.ttf": "BASE 64 HERE"
},
TimesNewRoman: {
"Roboto-Italic.ttf": "BASE 64 HERE",
"Roboto-Medium.ttf": "BASE 64 HERE",
"Roboto-Regular.ttf": "BASE 64 HERE"
}
}
我使用了与 Roboto 相同的字体作为测试,但它仍然无法正常工作。这是我回来的错误
Uncaught Error: No unicode cmap for font
下面是我的代码。您将此字符串粘贴到pdf tester here 中并查看结果
{
"content":[
{
"stack":[
{
"text":[
{
"text":""
}
]
},
{
"text":"ygjjkjgjkhjkjghk",
"style":"style_2",
"lineHeight":"1"
}
],
"style":"style_1"
},
{
"stack":[
{
"text":[
{
"text":""
}
]
},
{
"text":" ",
"style":"style_4",
"lineHeight":"1"
}
],
"style":"style_3"
},
{
"stack":[
{
"text":[
{
"text":""
}
]
},
{
"text":"",
"style":"style_7",
"font":"TimesNewRoman",
"lineHeight":"1"
},
{
"text":"sdfghfdghfghdgfgfh",
"style":"style_8",
"font":"TimesNewRoman",
"lineHeight":"1"
}
],
"style":"style_5"
}
],
"styles":{
"style_1":{
"opacity":"1"
},
"style_2":{
"opacity":"1"
},
"style_3":{
"opacity":"1"
},
"style_4":{
"opacity":"1"
},
"style_5":{
"opacity":"1"
},
"style_6":{
"opacity":"1"
},
"style_7":{
"font":"TimesNewRoman",
"opacity":"1"
},
"style_8":{
"opacity":"1"
}
},
"pageSize":"A4",
"pageOrientation":"portrait",
"pageMargins":[
40,
20,
40,
20
]
}
还有其他人使用过这个库吗?如果是这样,你是否使用了自定义字体,你是如何让它们工作的?如果需要,我可以发布更多代码,谢谢
【问题讨论】:
标签: javascript pdfmake