Print with batch

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

Print with batch

Postby robysimo09 » Wed Feb 24, 2010 6:46 pm

I'm trying to print via batch process a form with controller.print() but doesn't work.
In the sample solution I create a record in a table and try to print a form with a field.
The method works if I test it with a button in developer but if I run it with batch process doesn't work.
In attached a sample solution that needs to run like a batch.
The generation of a pdf works ( using the controller.print( true, false, plugins.pdf_output.getPDFPrinter(file_name)
No messages in servoy log or service log or in windows server log.
Thank's for help!
Bye
Roberto
prova.servoy
Install a server in windows server ( or xp ) and run the solution "prova" with a batch.
Create a user before.
Create a database server connection named "locale_bridgedata".
(9.73 KiB) Downloaded 361 times
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: Print with batch

Postby jcompagner » Thu Feb 25, 2010 10:57 am

what do you exactly expect to happen if you call controler.print() in a batck process?
Where should it print to?
What should it generate?

Your solution with the pdf printer is the way to go.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Print with batch

Postby robysimo09 » Thu Feb 25, 2010 11:31 am

I need to print a form directly to default printer.
In this sample form appear a field and a label.
In smart client and developer the method works ( print a page on default printer ).

Thank's for help.
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: Print with batch

Postby robysimo09 » Thu Feb 25, 2010 11:35 am

I can generate the pdf with pdf printer but I need to print directly to a printer.

Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: Print with batch

Postby jcompagner » Thu Feb 25, 2010 11:35 am

what default printer? Is there a printer attached to your server that you want to print on?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Print with batch

Postby robysimo09 » Thu Feb 25, 2010 11:36 am

yes.. the default printer attached to my server
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: Print with batch

Postby jcompagner » Thu Feb 25, 2010 11:45 am

thats not supported.

A batchclient can only print to pdf.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Print with batch

Postby robysimo09 » Thu Feb 25, 2010 11:51 am

Is it possible do that in future ( next releases )??
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: Print with batch

Postby jcompagner » Thu Feb 25, 2010 11:58 am

make a case for this that we can look at it.
But this is a very uncommon situation. All the servers i know dont have printers and are sitting in a datacenter far away from users who can pickup what the server printed...
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Print with batch

Postby robysimo09 » Thu Feb 25, 2010 12:02 pm

I already create a case for this problem/request.
I know that probably is not a common situation but we need this :)

Thank you for help!
Regards
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: Print with batch

Postby dpearce » Fri Feb 26, 2010 4:55 pm

Roberto,

I think i had a similar issue this week, wanting to create a print Q, but this code should help you i think?

The mac one is easy, except you need to make sure you specify the correct printer tray and paper, otherwise a light will come on and you will need to press a button on the print.

The windows one, you need to either put a setting in for the path to acrobat or make sure the user has acrobat 9 installed in the normal directories.
I am printing from blob fields, but you can equally print directly from a pdf created in a variable.

I think this should work for you as it doesnt touch the sides as it were.

David

Code: Select all
var tempFile = plugins.file.createTempFile('printfile','.pdf');
plugins.file.writeFile(tempFile, pdf);



if(utils.stringMiddle(application.getOSName(), 1, 7) == "Windows")
{
//var pathtoacrobat=plugins.dialogs.showInputDialog( 'path to acrobat',  'path to acrobat?', 'C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe' )
application.executeProgramInBackground('C:/Program Files/Adobe/Reader 9.0/Reader/AcroRd32.exe','/t',tempFile.getAbsolutePath())
}

else
{
//send the PDF to the printer
application.executeProgram( '/usr/bin/lpr',tempFile.getAbsolutePath(),"-o","media=a4,tray2");
}
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Print with batch

Postby david » Fri Feb 26, 2010 7:18 pm

dpearce wrote:Roberto,

I think i had a similar issue this week, wanting to create a print Q, but this code should help you i think?

The mac one is easy, except you need to make sure you specify the correct printer tray and paper, otherwise a light will come on and you will need to press a button on the print.

The windows one, you need to either put a setting in for the path to acrobat or make sure the user has acrobat 9 installed in the normal directories.
I am printing from blob fields, but you can equally print directly from a pdf created in a variable.

I think this should work for you as it doesnt touch the sides as it were.

David

Code: Select all
var tempFile = plugins.file.createTempFile('printfile','.pdf');
plugins.file.writeFile(tempFile, pdf);



if(utils.stringMiddle(application.getOSName(), 1, 7) == "Windows")
{
//var pathtoacrobat=plugins.dialogs.showInputDialog( 'path to acrobat',  'path to acrobat?', 'C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe' )
application.executeProgramInBackground('C:/Program Files/Adobe/Reader 9.0/Reader/AcroRd32.exe','/t',tempFile.getAbsolutePath())
}

else
{
//send the PDF to the printer
application.executeProgram( '/usr/bin/lpr',tempFile.getAbsolutePath(),"-o","media=a4,tray2");
}


Great code example. And with 5.1's new headless client plugin, you could run it on the server directly (also possible with a batch processor but not as elegant).
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Print with batch

Postby dpearce » Fri Feb 26, 2010 7:31 pm

Thanks David,

I should credit Scott Butler with putting me on the correct path. (viewtopic.php?f=15&t=13741)

The only thing to watch out for is stopping the printer blinking and asking you to load paper before actually printing on Mac. So you have to work out which tray to force it to go to. Even though mine was defualted A4, it needed to A4 otherwise the printer blinked US Letter, and i think it was trying to send it to the manual feed and only went to the paper tray when you hit the printer button. Forcing the tray in the code remedied that.

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Print with batch

Postby robysimo09 » Mon Mar 01, 2010 10:24 am

dpearce wrote:Roberto,

I think i had a similar issue this week, wanting to create a print Q, but this code should help you i think?

The mac one is easy, except you need to make sure you specify the correct printer tray and paper, otherwise a light will come on and you will need to press a button on the print.

The windows one, you need to either put a setting in for the path to acrobat or make sure the user has acrobat 9 installed in the normal directories.
I am printing from blob fields, but you can equally print directly from a pdf created in a variable.

I think this should work for you as it doesnt touch the sides as it were.

David

Code: Select all
var tempFile = plugins.file.createTempFile('printfile','.pdf');
plugins.file.writeFile(tempFile, pdf);



if(utils.stringMiddle(application.getOSName(), 1, 7) == "Windows")
{
//var pathtoacrobat=plugins.dialogs.showInputDialog( 'path to acrobat',  'path to acrobat?', 'C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe' )
application.executeProgramInBackground('C:/Program Files/Adobe/Reader 9.0/Reader/AcroRd32.exe','/t',tempFile.getAbsolutePath())
}

else
{
//send the PDF to the printer
application.executeProgram( '/usr/bin/lpr',tempFile.getAbsolutePath(),"-o","media=a4,tray2");
}



Thank's David

I tried to use acrobat command line with the method "application.executeProgramInBackground" but it runs only 3 times per batch process. I need to stop the AcroRd32.exe with taskmanager and after it will be performed up to a maximum of 3 trials. The system accept max 3 AcroRd32.exe process at the same time.

Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: Print with batch

Postby dpearce » Mon Mar 01, 2010 11:11 am

OK! I am about to test this this morning. Typical i used it once and assumed it would work.

If it doesnt work then.

1, A mac mini may be a good print Q server!

2. whatabout a second batch script that kills acrobat. What happens if you dont run in back ground? maybe then servoy kills the process once complete, instead of leaving it hanging.

I Will do some testing.

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Next

Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 6 guests

cron