Direct printing from webclient!

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

Direct printing from webclient!

Postby mboegem » Sat Feb 04, 2012 12:53 am

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:
Code: Select all
plugins.WebClientUtils.executeClientSideJS('window.print()');
   
   elements.myField.requestFocus(true);

- Have an onFocus method, attached to the 'myField' element do this:
Code: Select all
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!
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1750
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Direct printing from webclient!

Postby jcarlos » Sat Feb 04, 2012 1:24 am

This es excellent! Thanks a bunch. JC
Juan-Carlos Sanchez, Stanford University - Law and Economics
jcarlos
 
Posts: 578
Joined: Thu May 04, 2006 8:55 pm
Location: Palo Alto, California USA

Re: Direct printing from webclient!

Postby antonio » Fri Apr 06, 2012 1:59 am

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

Code: Select all
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)
Tony
Servoy 8 - 2022.03 LTS
antonio
 
Posts: 638
Joined: Sun Apr 02, 2006 2:14 am
Location: Australia

Re: Direct printing from webclient!

Postby Harjo » Fri Apr 06, 2012 11:05 am

mboegem wrote: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! :-)
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands


Return to How To

Who is online

Users browsing this forum: No registered users and 3 guests