pdfMake - open() and print() functions are not working

Please check that any type of ad blocker in your browser is turned off and try again.


I found solution for printing in same window.

In your .html file put iframe

<iframe id="printPdf" name="printPdf"></iframe>

iframe needs style to hide himself for example (I do not know why, but if I define width and height on iframe, printing will not work):

#printPdf { position: fixed; top: 0px; left: 0px; display: block;
            padding: 0px;border: 0px;margin: 0px;
            visibility: hidden; opacity: 0; 
}

Finally, just call:

    if ('safari') {
        pdfMake.createPdf(content).open({}, window.frames['printPdf']);
        setTimeout(function() {
            window.frames['printPdf'].focus();
            window.frames['printPdf'].print();
        }, 2000)
    } else {
        pdfMake.createPdf(content).print({}, window.frames['printPdf']);
    }

Tested on Chrome v72, Firefox v65, Edge v18, Safari v12