Direct printing from webclient!

The other day I had a customer request on a very simple - kind of - draft printout in webclient.
Normally you’d generate a PDF at serverside and provide the user with a download link or email with the pdf attached.
As this was really to much work for this simple functionality I came up with the solution below, which uses the WebClientUtils plugin.

  • Create a popupform with the printable content you need. (in my case just 1 text area)
  • Have an onShow method doing this:
plugins.WebClientUtils.executeClientSideJS('window.print()');
	
	elements.myField.requestFocus(true);
  • Have an onFocus method, attached to the ‘myField’ element do this:
var _oWin = controller.getWindow();
	_oWin.hide();
	_oWin.destroy();

That’s all!

Now as soon as you show this popupform, the browser print dialog will appear.
At this point the UI building is not yet completed (which does the trick here).
As soon as the print dialog is closed, the ‘myField’ will get focus and immediately trigger the onFocus method that will close the popupform.

Hope this can help others to get some easy printjobs going!

This es excellent! Thanks a bunch. JC

Hey, thanks for that! Can you think of a way to take that a step further, to skip the print dialog and print directly to the default printer? We save PDFs of invoices server side, and optionally printed client side. Some users have asked for a quicker way to print.

Currently we do this to tell the client to open file.pdf in a browser

var success = plugins.pdf_output.startMetaPrintJob()
controller.print(false,true,plugins.pdf_output.getPDFPrinter())
var pdfData = plugins.pdf_output.endMetaPrintJob()
plugins.file.writeFile("file.pdf", pdfData)

mboegem:
Normally you’d generate a PDF at serverside and provide the user with a download link or email with the pdf attached.

There is also an easy, (Servoy) way of doing this,

just place the text-area on a new form: myform

and do: forms.myform.controller.print() in the webclient.
Servoy will generate the pdf for you and push that automaticly to the weblcient! :-)