Print with batch

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[attachment=0]prova.servoy[/attachment]

prova.servoy (9.73 KB)

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.

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

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

Roberto

what default printer? Is there a printer attached to your server that you want to print on?

yes… the default printer attached to my server

thats not supported.

A batchclient can only print to pdf.

Is it possible do that in future ( next releases )??

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…

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

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

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:
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

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).

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:
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

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

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!

  1. 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

Roberto,

Just run our script on two pc’s in different buildings, and it printed 200 letters off. It just kept refreshing a single adobe window, which was left open, but with a blank screen at the end.

It certainly didnt seem to use multiple instances of adobe?

So basically worked fine. We are using reader 9.3 normal installation.

Hi David

I saw many istance of acrobat ( AcroRd32.exe ) in list of process via task manager.
I added the parameter “/n” in your example code; I need multiple istance of acrobat because I have many batch process for print: I cannot wait the end of 1st process but the 2nd must print at the same time. I can set different printer with controller.setPreferredPrinter( printer_name ) to print on different printers.
For example:
the first batch start and print on printer P1.
the second batch start at the same time of the 1st and print on printer P2.
The 2nd batch cannot wait the end of the 1st ( if the 2nd batch print on different printer otherwise is mandatory ).
We could print also 1000 pages at a time.

Thank’s David

This is a list of command line for acrobat.
http://stackoverflow.com/questions/6191 … -reference

Oh, i see now,
I am no expert at this, but just feeling my way in the dark!

Given the cost of hardware, if this is mission critical printing in bulk, you may be wise to have one PC box for each printer, and then use the scheduler plugin to run every X minutes to start the batch off. That would be one solution.

If you are saying it works with up to 3 instances of acrobat, and you can swap the printers successfully, then maybe if this is the maximum then you could do the above with one pc per 3 printers.

Someone else may have a better suggestion. I was content with one batch job running every hour. The thing though with printers, is that i also wanted someone to check the job had worked before moving all of the printQ records toprint=0 from toprint=1, as i dont trust printers just to keep on churning without jams and misfeeds etc.

Any other suggestions?

David

i would also say, just start 1 or more smart clients on the same pc as the server.
configure those to connect to the various printers and let them auto generate (through the scheduler) the reports.

What you were trying to do in the beginning will work in next Servoy 4 and Servoy 5 releases.
Batch clients and headless clients will execute the print command server-side if there is no printer job specified; but it will not show the print dialog, of course … even if you ask for it.

So you’ll just have to keep your fingers crossed that it will reach the correct printer. And you should use this carefully, so you don’t end up filling the server room with paper :).