jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Promise or callback after calling `.save(filename)` or `.output('save', filename)`

Open jimbuck opened this issue 11 years ago • 14 comments

Is there a way to fire a callback after the save action is complete? I'd like to only close a modal window after the file is "downloaded" so I need some way to act once it is complete.

I did see there is a PubSub class, how does that fit in to this library?

jimbuck avatar Jul 02 '15 14:07 jimbuck

+1

gustavolira avatar Nov 17 '15 16:11 gustavolira

+1

RobsonMathias avatar Nov 17 '15 16:11 RobsonMathias

+1

fabianoroberto avatar Jul 25 '16 10:07 fabianoroberto

+1

domagojhack avatar Sep 30 '16 17:09 domagojhack

Yeah that'd be great

MrRio avatar Sep 30 '16 17:09 MrRio

+1

Any update here?

uramonz avatar Oct 06 '16 16:10 uramonz

Would be neat to have this function. We would ideally want to redirect to another page only after the file has been created and saved to server as to avoid trying to access the file before it has been created.

hitolonen avatar Oct 27 '16 11:10 hitolonen

Although pull request by @raymondelferink shows as closed, jspdf.debug.js shows nothing related to a callback function for API.save can anyone confirm that a callback exists?

ankithkonda avatar Apr 10 '17 02:04 ankithkonda

Apparently there is no option to add a callback,, can anyone confirm this ?

Thanks...

carlosalarconb avatar Apr 25 '17 01:04 carlosalarconb

@carlosalarconb Please see comment I am posting on PR #1159

Flamenco avatar Apr 26 '17 18:04 Flamenco

added option returnPromise to save-method. will be part of next release.

var doc = new jsPDF(); doc.save('test.pdf', {returnPromise: true});

Uzlopak avatar Dec 04 '18 08:12 Uzlopak

Instead use {usePromise: true}, you should use {returnPromise: true}.

matheusgomes1 avatar Jan 17 '19 17:01 matheusgomes1

@matheusgomes1

You are right. While in development I changed it to returnPromise. Thank you. I edited my previous answer. ;)

Uzlopak avatar Jan 17 '19 18:01 Uzlopak

For anyone else not super up to speed on promise logic/syntax, here's how I leveraged this (awesome) returnPromise bit:

pdf.save("myfile.pdf", {returnPromise:true}).then(alert('PDF render all done!'));

cemerson avatar Jun 25 '19 11:06 cemerson