用JSPDF创建动态PDF
我需要创建一个动态的PDF。 文本内容可能会改变,因此他们的位置也可以改变。
标题COLS是这样的对象数组:
[
{
"title": "Vagas Ocupadas",
"dataKey": "occupiedVacancies"
},
{
"title": "Total de pés",
"dataKey": "totalFeet"
},
{
"title": "ID",
"dataKey": "id"
},
{
"title": "Local",
"dataKey": "movementLocation"
}
];
内容也是这样的对象数组:
[
{
"occupiedVacancies": "---",
"totalFeet": "---",
"id": 1,
"movementLocation": "Poita"
},
{
"occupiedVacancies": "---",
"totalFeet": "---",
"id": 8,
"movementLocation": "Garagem2"
},
{
"occupiedVacancies": 6,
"totalFeet": 471,
"id": 9,
"movementLocation": "Garagem"
}
];
需要将其下载到客户端,我尝试使用此信息:
let doc = new jsPDF({ orientation: 'landscape', unit: 'px', floatPrecision: 2 });
doc.setFont('Courier');
doc.table(20, 30, this.exportData, this.cols, {printHeaders: true, autoSize: true});
doc.save();
但是没有成功...它给了我这个错误:
getTextDimensions期望文本参数为字符串或类型 数字或一系列字符串。
I need to create a dynamic PDF.
The text content could change so their positions also.
The header cols is an object array like this:
[
{
"title": "Vagas Ocupadas",
"dataKey": "occupiedVacancies"
},
{
"title": "Total de pés",
"dataKey": "totalFeet"
},
{
"title": "ID",
"dataKey": "id"
},
{
"title": "Local",
"dataKey": "movementLocation"
}
];
And the content is also an object array like this:
[
{
"occupiedVacancies": "---",
"totalFeet": "---",
"id": 1,
"movementLocation": "Poita"
},
{
"occupiedVacancies": "---",
"totalFeet": "---",
"id": 8,
"movementLocation": "Garagem2"
},
{
"occupiedVacancies": 6,
"totalFeet": 471,
"id": 9,
"movementLocation": "Garagem"
}
];
It needs to be downloaded to the client, and I've tried using this:
let doc = new jsPDF({ orientation: 'landscape', unit: 'px', floatPrecision: 2 });
doc.setFont('Courier');
doc.table(20, 30, this.exportData, this.cols, {printHeaders: true, autoSize: true});
doc.save();
But without success... It gives me this error:
getTextDimensions expects text-parameter to be of type String or type
Number or an Array of Strings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信标题和数据的键应匹配。您的标题和内容中有不同的键。这可能是问题。
您还可以在此处查看类似的问题: https://github.com/parallax.com/parallax/jspdf/issues/ 3053
I believe keys of header and data should be matched. You have different keys in header and content. That may be the issue.
You can also check similar issue here: https://github.com/parallax/jsPDF/issues/3053