galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.14k stars 169 forks source link

TypeError: Unable to write page when calling writePage #484

Open muhammadhananraza opened 11 months ago

muhammadhananraza commented 11 months ago

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 11 months ago

disk is not available? file cannot be written to?

muhammadhananraza commented 11 months ago

@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 11 months ago

i dont know. looks ok.

muhammadhananraza commented 10 months ago

@galkahana does the library use/access disk internally?

galkahana commented 10 months ago

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