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

Memory heap while generating big amount of data #72

Open
spanwair-r opened this issue Mar 25, 2023 · 0 comments
Open

Memory heap while generating big amount of data #72

spanwair-r opened this issue Mar 25, 2023 · 0 comments

Comments

@spanwair-r
Copy link

I just want to mention problem while rendering big amount of data (lets say about 10 pages and more). on small instance server (1Gb memory and lower). There the problem appear and you will end up with memory heap error.
How to solve it:

  1. First of all every Nodejs servers are limited with heap memory, which is usually around 1.8Gb, so to solve it you have to increase heap to 4Gb at least (works for up to 60 pages text size data) with server start with flag --max_old_space_size=4096 exmp:
    node --max_old_space_size=4096 server.js
    for nx run you can use script in packagejson:
    "nx": "node --max_old_space_size=4096 ./node_modules/@nrwl/cli/bin/nx"
  2. if you get any of the images in the doc than remove it from the memory immediately you add them to rander, like this:
doc.image('path.jpg', 0, 480);
doc = doc._imageRegistry['path.jpg'];

when you use TS with img imported you use this:

const removeImageFromDoc = (doc: PDFDocument, image: '*.png') => {
 delete (doc as PDFDocument & { _imageRegistry: any })._imageRegistry[image];
 return doc;
};
doc.image(waterMark, 0, 480);
doc = removeImageFromDoc(doc, waterMark);

all of this can really help you to solve problem with rendering pdf on low level memory servers. I just faced same problems so I am sharing this out the world. Hope it helps someone.
Happy coding

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

1 participant