Revision f08036d7
Von Moritz Bunkus vor fast 9 Jahren hinzugefügt
SL/BackgroundJob/MassRecordCreationAndPrinting.pm | ||
---|---|---|
185 | 185 |
|
186 | 186 |
foreach my $local_printer_id ($printer_id, $copy_printer_id) { |
187 | 187 |
next unless $local_printer_id; |
188 |
my $printer = SL::DB::Printer->new(id => $local_printer_id)->load; |
|
189 |
my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command); |
|
190 |
if (!open $out, '|-', $command) { |
|
191 |
push @{ $data->{print_errors} }, { message => $::locale->text('Could not execute printer command: #1', $!) }; |
|
192 |
$job_obj->update_attributes(data_as_hash => $data); |
|
193 |
return; |
|
194 |
} |
|
195 |
binmode $out; |
|
196 |
print $out $self->{merged_pdf}; |
|
197 |
close $out; |
|
188 |
SL::DB::Printer |
|
189 |
->new(id => $local_printer_id) |
|
190 |
->load |
|
191 |
->print_document(content => $self->{merged_pdf}); |
|
198 | 192 |
} |
199 | 193 |
|
200 | 194 |
} |
SL/Controller/MassInvoiceCreatePrint.pm | ||
---|---|---|
325 | 325 |
} |
326 | 326 |
|
327 | 327 |
my $printer = SL::DB::Printer->new(id => $params{printer_id})->load; |
328 |
my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command); |
|
329 |
|
|
330 |
open my $out, '|-', $command or die $!; |
|
331 |
binmode $out; |
|
332 |
print $out $merged_pdf; |
|
333 |
close $out; |
|
328 |
$printer->print_document(content => $merged_pdf); |
|
334 | 329 |
|
335 | 330 |
flash_later('info', t8('The documents have been sent to the printer \'#1\'.', $printer->printer_description)); |
336 | 331 |
return $self->redirect_to(action => 'list_invoices', printer_id => $params{printer_id}); |
SL/Controller/Order.pm | ||
---|---|---|
182 | 182 |
} elsif ($media eq 'printer') { |
183 | 183 |
# printer |
184 | 184 |
my $printer_id = $::form->{print_options}->{printer_id}; |
185 |
my $printer; |
|
186 |
$printer = SL::DB::Printer->new(id => $printer_id)->load if $printer_id; |
|
187 |
if (!$printer) { |
|
188 |
return $self->js->flash('error', t8('Printer not found.'))->render; |
|
189 |
} |
|
190 |
|
|
191 |
my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command); |
|
192 |
|
|
193 |
for my $i (1 .. $copies) { |
|
194 |
open my $out, '|-', $command or die $!; |
|
195 |
binmode $out; |
|
196 |
print $out $pdf; |
|
197 |
close $out; |
|
198 |
} |
|
185 |
SL::DB::Printer->new(id => $printer_id)->load->print_document( |
|
186 |
copies => $copies, |
|
187 |
content => $pdf, |
|
188 |
); |
|
199 | 189 |
|
200 | 190 |
$self->js->flash('info', t8('The PDF has been printed')); |
201 | 191 |
} |
SL/DB/Printer.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
5 |
use Carp; |
|
6 |
|
|
5 | 7 |
use SL::DB::MetaSetup::Printer; |
6 | 8 |
use SL::DB::Manager::Printer; |
7 | 9 |
use SL::DB::Helper::Util; |
... | ... | |
23 | 25 |
return @errors; |
24 | 26 |
} |
25 | 27 |
|
28 |
sub print_document { |
|
29 |
my ($self, %params) = @_; |
|
30 |
|
|
31 |
croak "Need either a 'content' or a 'file_name' parameter" if !defined($params{content}) && !$params{file_name}; |
|
32 |
|
|
33 |
my $copies = $params{copies} || 1; |
|
34 |
my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($self->printer_command); |
|
35 |
my $content = $params{content} // scalar(File::Slurp::read_file($params{file_name})); |
|
36 |
|
|
37 |
for (1..$copies) { |
|
38 |
open my $out, '|-', $command or die $!; |
|
39 |
binmode $out; |
|
40 |
print $out $content; |
|
41 |
close $out; |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
26 | 45 |
1; |
46 |
__END__ |
|
47 |
|
|
48 |
=pod |
|
49 |
|
|
50 |
=encoding utf8 |
|
51 |
|
|
52 |
=head1 NAME |
|
53 |
|
|
54 |
SL::DB::Printer - Rose model for database table printers |
|
55 |
|
|
56 |
=head1 SYNOPSIS |
|
57 |
|
|
58 |
my $printer = SL::DB::Printer->new(id => 4711)->load; |
|
59 |
$printer->print_document( |
|
60 |
copies => 2, |
|
61 |
file_name => '/path/to/file.pdf', |
|
62 |
); |
|
63 |
|
|
64 |
=head1 FUNCTIONS |
|
65 |
|
|
66 |
=over 4 |
|
67 |
|
|
68 |
=item C<print_document %params> |
|
69 |
|
|
70 |
Prints a document by spawning the external command stored in |
|
71 |
C<$self-E<gt>printer_command> and sending content to it. |
|
72 |
|
|
73 |
The caller must provide either the content to send to the printer |
|
74 |
(parameter C<content>) or a name to a file whose content is sent |
|
75 |
verbatim (parameter C<file_name>). |
|
76 |
|
|
77 |
An optional parameter C<copies> can be given to specify the number of |
|
78 |
copies to print. This is done by invoking the print command multiple |
|
79 |
times. The number of copies defaults to 1. |
|
80 |
|
|
81 |
=back |
|
82 |
|
|
83 |
=head1 BUGS |
|
84 |
|
|
85 |
Nothing here yet. |
|
86 |
|
|
87 |
=head1 AUTHOR |
|
88 |
|
|
89 |
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt> |
|
90 |
|
|
91 |
=cut |
Auch abrufbar als: Unified diff
SL::DB::Printer: »Dokument an Drucker schicken« zentralisiert
Die neue Funktion print_document übernimmt das Spawnen des externen
Prozesses und schickt das Dokument an den Drucker. Das Dokument kann
entweder direkt als Inhalt oder als zu sendender Dateiname übergeben
werden.