typescriptpdfmake

Print more than one copy with pdfMake


I was using pdfMake for printing generated documents which works fine, but now I want to print more than one copy at a time. I have searched on the internet and on their documentation page with no luck, but a function as useful as being able to print more than once a document in the same call must had been implemented so clearly i'm doing something wrong.

My code:

function() {
// generation of the d content which i have already tested it generates the content right
const win = window.open('', "tempWinForPdf");
            pdfMake.createPdf(d).print({}, win);

            
            setTimeout(() => 
            {
                win.close();
            },
            this.printTime);
}

Print time is just a variable that contains in ms how many seconds should the window to wait before closing itself.

I have already tried things like

var dd = [d, d]

And then printing the dd which results in a blank page


Solution

  • In case someone has the same issue I resolved my problem waiting until the tab created closes and then I called again the function:

    async f(repeat: boolean) {
            ...
            const win = window.open('', "tempWinForPdf");
            pdfMake.createPdf(d).print({}, win);
    
            
            await new Promise((resolve) => setTimeout(resolve, this.printTime));
            win.close();
            if (repeat) {
                await this.f(false);
            }  
    }