TypeError: Unable to write page when calling writePage
muhammadhananraza opened this issue · 5 comments
muhammadhananraza commented
TypeError: Unable to write page when calling pdfWriter.writePage(current_page);
The error occurs occasionally (even with same data it works fine)
My initial hunch was resource (memory) limitation but that is not the case.
What could be the possible reason(s)?
galkahana commented
disk is not available? file cannot be written to?
muhammadhananraza commented
@galkahana we are not writing anything on disk. We are using stream writer (memory-streams npm package) to write in memory and then convert to buffer and return as response.
let ws = new require('memory-streams').WritableStream()
let pdfWriter = hummus.createWriter(new hummus.PDFStreamForResponse(ws));
......
......
......
let current_page = pdfWriter.createPage(0,0,page_width,page_height);
let cxt = pdfWriter.startPageContentContext(current_pagenot);
......
......
......
for loop data:
.....
.....
cxt.writeText(...)
pdfWriter.writePage(current_page); // the error occurs here
current_page = pdfWriter.createPage(0, 0, page_width, page_height);
cxt = pdfWriter.startPageContentContext(current_page);
.....
.....
....
....
....
cxt.writeText(...)
pdfWriter.writePage(current_page);
pdfWriter.end();
let bufferResult = ws.toBuffer();
ws.end();
return bufferResult;
galkahana commented
i dont know. looks ok.
muhammadhananraza commented
@galkahana does the library use/access disk internally?
galkahana commented
No. Itll write to a file only if you asked it to, and read from it only if you gave it something to read (images, fonts, etc.)