Bug 8007: Replace HTML::HTMLDoc with PDF::FromHTML

Signed-off-by: Lucie <lucie.rousseaux@dracenie.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2014-12-18 15:39:46 +01:00 committed by Tomas Cohen Arazi
parent 5d7aae6fde
commit a72cda3d9d
2 changed files with 13 additions and 7 deletions

View file

@ -737,10 +737,10 @@ our $PERL_DEPS = {
'required' => '0',
'min_ver' => '5.61',
},
'HTML:HTMLDoc' => {
'PDF::FromHTML' => {
'usage' => 'Discharge generation',
'required' => '0',
'min_ver' => '0.07',
'min_ver' => '0.31',
},
};

View file

@ -3,7 +3,7 @@ package Koha::Borrower::Discharge;
use Modern::Perl;
use CGI;
use File::Temp qw( :POSIX );
use HTML::HTMLDoc;
use PDF::FromHTML;
use C4::Members qw( GetPendingIssues );
use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve );
@ -108,10 +108,16 @@ sub generate_as_pdf {
messages => [$letter],
);
my $pdf_path = tmpnam();
my $htmldoc = new HTML::HTMLDoc();
$htmldoc->set_html_content($tmpl->output);
$htmldoc->generate_pdf()->to_file($pdf_path);
my $html_path = tmpnam() . '.html';
my $pdf_path = tmpnam() . '.pdf';
my $html_content = $tmpl->output;
open my $html_fh, '>', $html_path;
say $html_fh $html_content;
close $html_fh;
my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
$pdf->load_file( $html_path );
$pdf->convert;
$pdf->write_file( $pdf_path );
return $pdf_path;
}