How to print without print dialog

How can I write a method that prints without the print dialog?

I have a method that loops through a found set of records and prints form A and form B for each record. If form B does not contain data then it is skipped (not printed).

The looping and conditions are not a problem. I am stuck on what should be the easy part. When each form needs to be printed, how do I have the method print the form without having the print dialog come up?

I think there is a flag in controller.print allowing you to print without a dialog. At least it lets you print a whole batch showing the print dialog only once…

Yes, there is a flag that lets you print the current record or current found set of records, and that is good.

However, in this case I need to do the following without repeatedly showing print dialogs:

  1. go to first record
  2. print form A (first page of form)
  3. print form B (second page of form) if attachment field contains text
    repeat steps 2 and 3 for remaining records

This seems like it should be so simple, but I’m stumped. Does anyone know if this can be done in Servoy?

I have come across that, too, and found no solution. I’d be interested to hear if there is a way! I think the situation is a frequent one. I have one page that is portrait and one that is landscape. Both pages have to be printed for each single (!) record. I don’t want someone to sort those together manually from two piles. How do I do that?

Thanks
Patrick

What about [ShowPrinterSelectDialog] in controller.print? I use it to show the print-dialog only once when printing a batch of invoices. I set to true on the first print command, false thereafter.

if(plugins.dialogs.showQuestionDialog('Print','Batch Print Invoices?','Yes','No') == 'No') {
	return '';
}
for ( var i = 1; i <= foundset.getSize() ; i++ )
{
	foundset.setSelectedIndex(i);
	if(i == 1) {
		forms.acc_document_detail.document_print(true,true,'');
	} else {
		forms.acc_document_detail.document_print(true,false,'');
	}
}

controller.saveData();	
plugins.dialogs.showInfoDialog('Batch Print Invoices','Done!','OK');

and

var automatic = arguments[0];
var show_printer_select = arguments[1];
var email_pdf_to =  arguments[2];
controller.saveData();

.
.
.
.
.
	} else if(automatic) {
		forms.acc_transaction_list_print.controller.print(false,show_printer_select);
	} else {
		forms.acc_transaction_list_print.controller.showPrintPreview();
	}

.
.
.
.

The solution Christian uses is exactly the way I solved such an issue also!

Thank you all! The following appears to solve my problem:

if(plugins.dialogs.showQuestionDialog('Print',
'Print found set (also prints page 2 when page 2 "attachment" field '+
'contains at least one word)?','Yes','No') == 'No')
{ 
   return ''; 
} 
controller.recordIndex = 1;
for ( var i = 1; i <= foundset.getSize() ; i++ ) 
{ 
foundset.setSelectedIndex(i); 
forms.formA.controller.print(true,false);
if(utils.stringWordCount(attachment) > 0)
	{
	forms.formB.controller.print(true,false);
	}
} 
controller.recordIndex = 1;
plugins.dialogs.showInfoDialog('Print Status','Print job completed!','OK');

I am a little confused here.

so when you first show the printerdialog, choose an other printer as the default, than the rest of the pages(forms) are printed to that printer also???

HJK:
I am a little confused here.

so when you first show the printerdialog, choose an other printer as the default, than the rest of the pages(forms) are printed to that printer also???

What are you confused about? Did you try it? What would you expect? What were your results? In which sense and why were they confusing? Any changes you suggest?

Apologies for the amount of questions but I always want to know what’s going on when people are a little confused.

Is it forbidden to be confused? :?

I had the assumption (and still have) that when you show a printer dialog and print a job, and right after that you do another printjob, that the last print-job ends is printed to the default-printer and NOT the printer thas has been choosen the first time!

for example, when you do this:

forms.printOrder.controller.print(true,true)
forms.printFax.controller.print(true,false)

the first line is printed to the printer you select.
the second line is printed always to the default printer.
(I double checked it now!)
Showing a printerdialog in this case, has no sense to me, because the rest that follows is always printed to the default printer.

So yes, I would like to have a function, where Servoy could ‘remember’ what the last choosen printer was.