+sub _print_invoice {
+ my ($invoice, $config) = @_;
+
+ return unless $config->print && $config->printer_id && $config->printer->printer_command;
+
+ my $form = Form->new;
+ $invoice->flatten_to_form($form, format_amounts => 1);
+
+ $form->{printer_code} = $config->printer->template_code;
+ $form->{copies} = $config->copies;
+ $form->{formname} = $form->{type};
+ $form->{format} = 'pdf';
+ $form->{media} = 'printer';
+ $form->{OUT} = $config->printer->printer_command;
+ $form->{OUT_MODE} = '|-';
+
+ $form->prepare_for_printing;
+
+ $form->throw_on_error(sub {
+ eval {
+ $form->parse_template(\%::myconfig);
+ 1;
+ } || die $EVAL_ERROR->getMessage;
+ });
+}
+