diff --git a/sites/all/modules/print/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc b/sites/all/modules/print/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc
index 3e86f97..191e56b 100644
--- a/sites/all/modules/print/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc
+++ b/sites/all/modules/print/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc
@@ -49,30 +49,37 @@
     $wkhtmltopdf_options .= ' --username ' . check_plain($_SERVER['PHP_AUTH_USER']) . ' --password ' . check_plain($_SERVER['PHP_AUTH_PW']);
   }
 
-  $descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'a'));
-  $cmd = '"' . realpath($pdf_tool[1]) . "\" --page-size $paper_size --orientation $page_orientation --dpi $dpi $wkhtmltopdf_options - -";
-
-  $process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
-
-  if (is_resource($process)) {
-    fwrite($pipes[0], $html);
-    fclose($pipes[0]);
-
-    $pdf = stream_get_contents($pipes[1]);
-    fclose($pipes[1]);
-
-    stream_set_blocking($pipes[2], 0);
-    $error = stream_get_contents($pipes[2]);
-    fclose($pipes[2]);
-
-    $retval = proc_close($process);
-    if (!empty($error) || ($retval != 0)) {
-      if (empty($error)) {
-        $error = 'No stderr output available.';
-      }
-      watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error', array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
+   // Write the data to a temporary file.
+  $temp_path = realpath(file_directory_temp()) . '/';
+  $temp_html =  false;
+  $temp_pdf = false;
+  $retries=0;
+  while (($temp_html==false) && ($retries<10)) {
+    $temp_html =  drupal_tempnam($temp_path, 'c_html_');
+    if (rename($temp_html, $temp_html.'.html')) {
+      $temp_html = $temp_html.'.html';
     }
+    
+    $retries++;
   }
+  while (($temp_pdf==false) && ($retries<20)) {
+    $temp_pdf =  drupal_tempnam($temp_path, 'c_pdf_');
+    if (rename($temp_pdf, $temp_pdf.'.pdf')) {
+      $temp_pdf = $temp_pdf.'.pdf';
+    }
+    $retries++;
+  }
+  watchdog('devel', "temp_html: $temp_html temp_pdf: $temp_pdf");
+  if (file_put_contents($temp_html, $html) === FALSE) {
+    return FALSE;
+  }
+  $cmd2 = '"' . realpath($pdf_tool[1]) . "\" --page-size $paper_size --orientation $page_orientation --dpi $dpi $wkhtmltopdf_options $temp_html $temp_pdf";
+  watchdog('devel2', $cmd2);
+  exec($cmd2);
+
+  $pdf= file_get_contents($temp_pdf);
+  unlink($temp_html);
+  unlink($temp_pdf);
 
   if (!empty($pdf)) {
     return $pdf;
