I am currently utilizing pdfMake to create PDFs from observable data, but I am encountering an issue where the PDF either appears empty or displays [object Object]. Below is the snippet of my code:
downloadPDF() {
pdfMake.vfs = pdfFonts.pdfMake.vfs;
var docDefinition = {
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(docDefinition);
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();
}
}
Note: The observableData variable contains values from Firebase documents.