Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Unable to write page when calling writePage #484

Open
muhammadhananraza opened this issue Aug 7, 2023 · 5 comments
Open

TypeError: Unable to write page when calling writePage #484

muhammadhananraza opened this issue Aug 7, 2023 · 5 comments

Comments

@muhammadhananraza
Copy link

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
Copy link
Owner

disk is not available? file cannot be written to?

@muhammadhananraza
Copy link
Author

muhammadhananraza commented Aug 7, 2023

@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
Copy link
Owner

i dont know. looks ok.

@muhammadhananraza
Copy link
Author

@galkahana does the library use/access disk internally?

@galkahana
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants