nbesli/pdf-merger-js

JavaScript heap out of memory

Closed this issue · 1 comments

Hello,

I am trying with library to merge two PDFs, one 20 pages, one about 600 pages. I watch as it cosumes multiple GB of RAM and then eventually crashes my node server.

Is this not meant for files with large amount of pages or am I doing something wrong?
What I'm doing looks something like this:

merger.add(file1, [1]);
merger.add(file2, '2-618');

I've have been looking for the most efficient means of creating PDFs from source files as I need to do it on a rather large scale (lots of documents, lots of pages per document, constant requests). I have gone the ghostscript/ImageMagick route in the past of converting PDF to PNG (which is slow) and then PNG to PDF (which is relatively quick). In my scenario I could avoid doing the PDF to PNG if I have a good library that can handle merging of PDFs together (with specific page instructions)...just like this library supports.

The problem is that this library is (surprisingly) very resource intensive. To the point of crashing with a couple hundred pages after consuming 10+ GB of RAM. I feel like something must be wrong here as this shouldn't be no intensive.