Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdfMake callback when export is finished

Is there a way to specify a callback function for the pdfMake's createPdf function? I have a large vfs_fonts.js file and that's why my export is slow.

like image 547
István Avatar asked Oct 15 '25 23:10

István


1 Answers

There is a callback function getDataUrl:

this.getDataUrl(function(result) {
    win.location.href = result;
});

This function is used by the open, save, and print functions that come built in. You can see their source here: https://github.com/bpampuch/pdfmake/blob/81de2c6a97ffb102f8c8c86ea9d7adf97e65976e/src/browser-extensions/pdfMake.js#L50

Using those functions, you should be able to build your own callback that does what you need.

You can use getDataUrl with something like

pdfMake.createPdf(docDefinition).getDataUrl(function(url) { alert('your pdf is done'); });

You would of course want more than that since you want to give them a way to do something with the completed PDF.

To add a callback after the download is done:

pdfMake.createPdf(docDefinition).download('file.pdf', function() { alert('your pdf is done'); });
like image 70
Loren Avatar answered Oct 17 '25 11:10

Loren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!