]*?)>!is'; $html = preg_replace_callback($pattern, '_print_replace_spaces', $html); } // dompdf seems to have problems with something in system.css so let's not use it $html = preg_replace('!!', '', $html); $url_array = parse_url($meta['url']); $protocol = $url_array['scheme'] . '://'; $host = $url_array['host']; $path = dirname($url_array['path']) . '/'; $dompdf = new DOMPDF(); $dompdf->set_base_path($path); $dompdf->set_host($host); $dompdf->set_paper(drupal_strtolower($paper_size), $page_orientation); $dompdf->set_protocol($protocol); // dompdf can't handle footers cleanly, so disable the following // $html = theme('print_pdf_dompdf_footer', array('html' => $html)); // If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and then to HTML entities if (!$unicode) { // Convert the euro sign to an HTML entity $html = str_replace('€', '€', $html); // Convert from UTF-8 to ISO 8859-1 and then to HTML entities if (function_exists('utf8_decode')) { $html = utf8_decode($html); } // iconv fails silently when it encounters something that it doesn't know, so don't use it // else if (function_exists('iconv')) { // $html = iconv('UTF-8', 'ISO-8859-1', $html); // } elseif (function_exists('mb_convert_encoding')) { $html = mb_convert_encoding($html, 'ISO-8859-1', 'UTF-8'); } elseif (function_exists('recode_string')) { $html = recode_string('UTF-8..ISO_8859-1', $html); } $html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'ISO-8859-1'), ENT_NOQUOTES); } else { // Otherwise, ensure the content is properly formatted Unicode. $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); } // Must get rid of tbody (dompdf goes into recursion) $html = preg_replace('!]*?>|!i', '', $html); $dompdf->load_html($html); $dompdf->render(); return $dompdf->output(); } /** * Format the dompdf footer contents * * @param array $vars * An associative array containing: * - $html: contents of the body of the HTML from the original node * * @return string * customized HTML text * * @ingroup themeable * @ingroup print_themeable */ function theme_print_pdf_dompdf_footer($vars) { preg_match('!!si', $vars['html'], $tpl_footer); if (isset($tpl_footer[1])) { $html = str_replace($tpl_footer[0], '', $vars['html']); $text = ''; return str_replace("", "" . $text, $html); } else { return $vars['html']; } }