From e399318f243d5781ec1367ea676e059f64d5bae1 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Mon, 14 Dec 2015 14:45:57 +0000
Subject: [PATCH] Bug 8352 [QA Followup] - Remove use of HTML::HTMLDoc

---
 C4/Installer/PerlDependencies.pm |  5 -----
 Koha/Printer.pm                  | 24 ++++++++++++++++++------
 debian/control.in                |  2 ++
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm
index 82f1245..1a3cba5 100644
--- a/C4/Installer/PerlDependencies.pm
+++ b/C4/Installer/PerlDependencies.pm
@@ -632,11 +632,6 @@ our $PERL_DEPS = {
         'required' => '0',
         'min_ver'  => '1.11',
     },
-    'HTML::HTMLDoc' => {
-        'usage'    => 'Push to printer',
-        'required' => '0',
-        'min_ver'  => '0.10',
-    },
     'File::Temp' => {
         'usage'    => 'Plugins',
         'required' => '0',
diff --git a/Koha/Printer.pm b/Koha/Printer.pm
index c7965e2..da0385a 100644
--- a/Koha/Printer.pm
+++ b/Koha/Printer.pm
@@ -50,12 +50,24 @@ sub print {
     return unless ($data);
 
     if ($is_html) {
-        require HTML::HTMLDoc;
-        my $htmldoc = new HTML::HTMLDoc();
-        $htmldoc->set_output_format('ps');
-        $htmldoc->set_html_content($data);
-        my $doc = $htmldoc->generate_pdf();
-        $data = $doc->to_string();
+        require PDF::FromHTML;
+        require File::Temp;
+        require File::Slurp;
+
+        my ( $pdf_fh, $pdf_filename ) = File::Temp::tempfile();
+        my ( $ps_fh,  $ps_filename )  = File::Temp::tempfile();
+
+        my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
+        my $pdf_data;
+        $pdf->load_file( \$data );
+        $pdf->convert();
+        $pdf->write_file( $pdf_filename );
+
+        `pdf2ps $pdf_filename $ps_filename`;
+
+        $data = File::Slurp::read_file( $ps_filename );
+
+        unlink( $pdf_filename, $ps_filename );
     }
 
     my ( $result, $error );
diff --git a/debian/control.in b/debian/control.in
index ad9b891..11c3ef7 100644
--- a/debian/control.in
+++ b/debian/control.in
@@ -22,6 +22,7 @@ Depends: ${misc:Depends}, ${koha:Depends},
  cron-daemon,
  daemon,
  debconf,
+ ghostscript,
  idzebra-2.0,
  libjs-jquery,
  mysql-client | virtual-mysql-client,
@@ -70,6 +71,7 @@ Depends: ${misc:Depends},
  cron-daemon,
  daemon,
  debconf,
+ ghostscript,
  idzebra-2.0,
  libjs-jquery,
  mysql-client | virtual-mysql-client,
-- 
2.1.4