edabg / jsprintsetup

JSPrintSetup Firefox addon
Mozilla Public License 2.0
76 stars 39 forks source link

is jsPrintSetup.print(); synchronous or asynchronous #45

Open BluewaterBeach opened 7 years ago

BluewaterBeach commented 7 years ago

I am using JSPrintSetup to generate a PDF file and a PS file. I need to know if I can just do: <script> ... jsPrintSetup.setOption('outputFormat', 'PDF'); jsPrintSetup.setOption('toFileName', 'output.pdf'); jsPrintSetup.print(); jsPrintSetup.setOption('outputFormat', 'PS'); jsPrintSetup.setOption('toFileName', 'output.ps'); jsPrintSetup.print(); </script> That would call one output process after the other. The assumption is that the PDF file is completely generated in a synchronous way and that function is completed. Then it is clear to change the settings and call print() again to generate the PS file.

If it is asynchronous, then calling print() returns immediately and then there might be an issue changing the jsPrintSetup options and calling print again.

I would assume it is synchronous but a lot of javascript libraries use async. It isn't clear in the docs.

Great add-on!

Thanks! Alex.

mitkola commented 7 years ago

jsPrintSetup.print() is asynchronous. The simplest way is to give timeout between calls.

BluewaterBeach commented 7 years ago

any chance you could give me an example. Thanks!

mitkola commented 7 years ago

You can see sample here https://github.com/edabg/jsprintsetup/issues/35#issuecomment-274731943