I having a problem printing from webclient. When I print, only the bottom page of a 2 page print job prints or shows in print preview. Does anyone know what I’m doing wrong here?
How are you attempting to print? Instead of printing straight from a browser, we use a Servoy method to print to a PDF file. Our experience has been that this results in very accurate printouts (we use the Arial font).
Thank you I’ll try that. Would you happen to have an example of such a method.
Attach a form method to your print button:
forms.yourformname.controller.show();
globals.print_foundset_currentform(true,true);
Create a global print_foundset_currentform method that can be used with any form or list:
var allor1 = false
if(arguments[0]=='true') allor1 = true
var returnafterprint = arguments[1]
if(application.getApplicationType()==5)
{
//if web-client print to pdf and open it
//to print without printdialog to pdf file in temp dir.
var fname = currentcontroller.getName() + '_print'
if (!forms[fname]) fname = currentcontroller.getName()
var installdir = java.lang.System.getProperty("user.dir")
var rnd = Math.round(Math.random()*10000000000)
var filepath = installdir + '/server/webapps/ROOT/pdf/pf' + rnd + '.pdf'
application.output('printing form with name: ' +fname)
forms[fname].controller.print(allor1,false,plugins.pdf_output.getPDFPrinter(filepath));
history.go(-1)
application.showURL('/pdf/pf'+rnd+'.pdf','_self')
}
else
{
currentcontroller.print( allor1, true);
if (returnafterprint) history.go(-1)
}
To print one record on a form create and use a global print_current_currentform method the same as above, except with:
forms[fname].controller.print(true,true,plugins.pdf_output.getPDFPrinter(filepath));
It is also possible to provide the user with x and y coordinate fields and allow the user to enter how many pixels they want to adjust the print margins. Then when they click the print button the margins within the PDF form will be instantly adjusted on the fly.
Thanks to Servoy for their great support of Acrobat PDF forms!
Dean Westover
Dean I can’t thank you enough for your help! That worked well! I’m so fired up! It still only prints a single page form, but it does it in pdf and that is great because that was something that the client had asked for. I just compressed the form so it fit on one page. 8.5x11.
At first it didn’t work because I hadn’t created the pdf directory in the root folder. Freshman mistake on my part, I should have seen that right off. When you create pdfs, does your form even exceed one one page length and if so how do you deal with that?
Dean thanks so much! I sure you’re very busy so I really appreciate you taking the time.
Hi Dean, I don’t understand why you are doing this yourself.
If you do just controller.showPrintPreview() than Servoy webclient does this all for you!. It will print the page to pdf and show it in the browser.
What is different in your approach?
All of our forms are 8 1/2 by 11 inches or smaller, except for the lists and they print to PDF fine. It sounds like you are already using paperPrintScale to compress the form into one page. Under defaultPageFormat the Paper Size popup does have a “Custom Size…” option at the very bottom of the list. I am not sure what affect this would have on the PDF output. I am a little surprised that large forms are not just overflowing to a new PDF page.
Hi Harjo,
Yes, the above code pre-dates what you describe, but may include some features that help some people. Whatever works for you - go with it.
Dean
Yeah Dean I was very surprised that it did flow into a second page. I sure it’s something I’m not getting write.
I’ll have to keep working at it
I try the method Harjo sited, it also works but is more click and not as elegant as Deans method (this in reference to WebClient). It’s a toss-up in smart client. This is just my opinion!
The great people at Servoy created and deserve credit for both approaches. It was good of Harjo to point out the easier way.
Dean