From 7440c47da9503e81df0ed78a2e61feba43f3cec4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 18 Dec 2014 15:39:46 +0100 Subject: [PATCH] Bug 8007: Replace HTML::HTMLDoc with PDF::FromHTML --- C4/Installer/PerlDependencies.pm | 4 ++-- Koha/Borrower/Discharge.pm | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 7879596..7cedd6f 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -742,10 +742,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', }, }; diff --git a/Koha/Borrower/Discharge.pm b/Koha/Borrower/Discharge.pm index 6027e7e..1665bc7 100644 --- a/Koha/Borrower/Discharge.pm +++ b/Koha/Borrower/Discharge.pm @@ -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; } -- 2.1.0