galkahana/HummusJS

TypeError: Unable to write page when calling writePage

muhammadhananraza opened this issue · 5 comments

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)?

disk is not available? file cannot be written to?

@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;

i dont know. looks ok.

@galkahana does the library use/access disk internally?

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.)