I am new here and i need your help to find a solution for my crash problem.
I am building a reactjs app and creating a pdf document and then download it by using
pdfmake.createPdf.download
However, when pdf size is too big, browser gives error and crashes. Therefore, I am trying to divide pdf into smaller chunks and download them one by one. But it executes all download methods and downloads multiple pdf at the same time. And this does not solve my issue because I believe I need to give back the allocated memory in order to prevent the crash.
I searched for answers but none of them worked in my case. Still crash happens.
Here is how my code basically looks like
exportPdf(rowData)
{
let org = rowData.details;
let startIndex = 0;
let endIndex = 0;
while(lastIndex != -1)
{
startIndex = endIndex;
endIndex += 25;
if(endIndex > org.length)
{
lastIndex = -1;
}
rowData.details = org.slice(startIndext, endIndex);
pdfMake.createPdf( createDocumentContent(rowData) ).download();
}
}
I want Chrome to download the file for every iteration. I tried to use Promise, setInterval but didnt work. I also increased nodejs heap size by increasing --max_old_space_size to prevent the crash, also didnt work.
I use react scripts to create build and deploy it under webbapps for apache-tomcat-9.0.14. And my node version is v10.15.3.
I appreciate any help you can offer.
Thanks in advance.