Search code examples
javascriptangularjspdfmake

Download multiple files using pdfMake


Excuse me, I am using pdfMake plugin in my angular. https://github.com/bpampuch/pdfmake I would like to download multiple files (different docs definition). I have an array of Docs. when I loop the array and call the function download, the number of files i get depends on the length of array which is right, but the Docs are all the same (the last doc of array is the content of every file).

However, in that array when i log in console, the docs are different. Any solutions for this issue. I do need your help. Every answer would be appreciated.


Solution

  • After trying finding many solutions, I come up with the setInterval. so I set the time interval to each download. It works well for me.

    var index = 0;
    var interval = setInterval(function()
        {
            if (index < docArray.length){ // docArray here is array of docs contents
                pdfMake.createPdf(docArray[index]).download('Export.pdf');
                index++;
            }
            else {
                clearInterval(interval);
            }
        },
        200);
    

    Thanks for this http://eysermans.com/post/sequentially-download-multiple-files-with-jquery that enables me to go on my task.