【发布时间】:2021-09-20 07:18:56
【问题描述】:
我正在使用 pdfMake 从可观察数据生成 PDF,但它在 PDF 中返回空或 [object Object]。 这是我的代码:
downloadPDF() {
pdfMake.vfs = pdfFonts.pdfMake.vfs;
var docDefination = {
content: [
{
text: "lightHorizontalLines:",
fontSize: 14,
bold: true,
margin: [0, 20, 0, 8],
},
{
style: "tableExample",
table: {
headerRows: 1,
body: [
[{ text: "Details", style: "tableHeader" }],
[{ text: this.observableData }], // observable to pdf data not showing here.
],
},
layout: "lightHorizontalLines",
},
],
};
this.pdfObj = pdfMake.createPdf(docDefination);
if (this.plt.is("cordova")) {
this.pdfObj.getBase64(async (data) => {
try {
let path = `pdf/myletter_${Date.now()}.pdf`;
const result = await Filesystem.writeFile({
path,
data: data,
directory: FilesystemDirectory.Documents,
recursive: true,
});
this.fileOpener.open(`${result.uri}`, "application/pdf");
} catch (error) {
console.log("Unable to write file: ", error);
}
});
} else {
this.pdfObj.download();
}
}
注意:observableData 包含 firebase 文档值。
【问题讨论】:
-
使用。
JSON.parse(this.observableData) -
'Observable
' 类型的参数不可分配给'string'.ts(2345) 类型的参数我得到这个错误
标签: angular typescript cordova ionic-framework pdfmake