我在Heroku上有一个应用程序,我在其中生成一系列画布的PDF,但它经常超过512mb的内存配额,即使画布是空的。我认为问题出在canvas.loadFromJSON()
这里是我使用的代码。任何帮助都非常感谢。
doc = new PDFDocument({size:[pageWidth, pageHeight]})
for (var i = 1; i < 9; i++) {
canvas = new fabric.StaticCanvas()
canvas.setWidth(canvasWidth)
canvas.setHeight(canvasHeight)
if ( publication && publication.pages.hasOwnProperty('p' + i) ) { // if not empty
canvas.loadFromJSON(publication.pages['p' + i])
delete publication.pages['p' + i]
SVGtoPDF(doc, canvas.toSVG(), 0, 0)
canvas.clear()
canvas.dispose()
if (i != 8) {
doc.addPage()
}
}
delete publication
delete canvas
}
doc.pipe(res).on('finish', function() {
console.log('single page pdf was successfully created by ' + process.pid)
})
doc.end()