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!