Using NodeJs I'm trying to write a small API with Grapecity SpreadJs library. In my project I have installed the following libraries:
When I try to call savePDF() on a Workbook instance, I have this error: savePDF() is not a function. Here my code:
GC.Spread.Sheets.LicenseKey = "myKey";
SJSExcel.LicenseKey = "myKey";
var wb = new GC.Spread.Sheets.Workbook();
var invoice = JSON.parse(fs.readFileSync("./invoice_data/invoice_example.json"));
wb.fromJSON(invoice);
wb.savePDF(function (blob) {
var fileName = 'download';
saveAs(blob, fileName + '.pdf');
},
function (error) {
console.log(error);
}
});
What's wrong?
Thanks in advance.
I am a member of GrapeCity's Technical Engagement team. I wanted to share that a NodeJS environment cannot support SpreadJS's PDF export.
The reason is that SpreadJS’s PDF export feature has a deep dependency on the DOM object. When exporting SpreadJS to a PDF, it is changing the graphic context from canvas to a PDF context. This requires going over all the rendering logic and requesting a lot of DOM element computing. The NodeJS environment uses a Mock jsDom that cannot provide the deep dependency that is needed and for this reason, a NodeJS environment cannot support SpreadJS exporting a PDF.
If you have any questions, feel free to reach out to the SpreadJS team here: Submit a Ticket