- my $input_names = join ' ', String::ShellQuote::shell_quote(@{ $params{file_names} });
- my $exe = $::lx_office_conf{applications}->{ghostscript} || 'gs';
- my $output = `$exe -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${temp_name} ${input_names} 2>&1`;
+ my $input_names = '';
+ my $hasodd = 0;
+ my $emptypage = '';
+ if ($params{bothsided}) {
+ $emptypage = $::instance_conf->get_templates . '/emptyPage.pdf';
+ unless (-f $emptypage) {
+ $emptypage = '';
+ delete $params{bothsided};
+ }
+ }
+ if ($params{inp_content}) {
+ my ($temp_fh, $inp_name) = File::Temp::tempfile(
+ 'kivitendo-contentXXXXXX',
+ SUFFIX => '.pdf',
+ DIR => $::lx_office_conf{paths}->{userspath},
+ UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1,
+ );
+ binmode $temp_fh;
+ print $temp_fh $params{inp_content};
+ close $temp_fh;
+ $input_names = $inp_name . ' ';
+ $hasodd = $params{bothsided} && __PACKAGE__->has_odd_pages($inp_name);
+ }
+ foreach (@{ $params{file_names} }) {
+ $input_names .= $emptypage . ' ' if $hasodd;
+ $input_names .= String::ShellQuote::shell_quote($_) . ' ';
+ $hasodd = $params{bothsided} && __PACKAGE__->has_odd_pages($_);
+ }
+ my $exe = $::lx_office_conf{applications}->{ghostscript} || 'gs';
+ my $output =
+ `$exe -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${temp_name} ${input_names} 2>&1`;