print_pdf_mpdf.pages.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * Generates the PDF version using mPDF
  5. *
  6. * This file is included by the print_pdf_mpdf module and includes the
  7. * functions that interface with the mPDF library
  8. *
  9. * @ingroup print
  10. */
  11. /**
  12. * Implements hook_print_pdf_generate().
  13. */
  14. function print_pdf_mpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
  15. module_load_include('inc', 'print', 'includes/print');
  16. $pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
  17. if (empty($paper_size)) {
  18. $paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
  19. }
  20. if (empty($page_orientation)) {
  21. $page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
  22. }
  23. $content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
  24. $images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
  25. if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
  26. if (!defined('_MPDF_TTFONTDATAPATH')) define('_MPDF_TTFONTDATAPATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/ttfontdata/'));
  27. if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/tmp/'));
  28. }
  29. require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
  30. $format = ($page_orientation == "landscape") ? $paper_size . "-L" : $paper_size;
  31. // Try to use local file access for image files
  32. $html = _print_access_images_via_file($html, $images_via_file);
  33. // set document information
  34. $mpdf = new mPDF('UTF-8', $format);
  35. $mpdf->SetAuthor(strip_tags($meta['name']));
  36. $mpdf->SetCreator(variable_get('site_name', 'Drupal'));
  37. // Pulled from the HTML meta data
  38. // $mpdf->SetTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
  39. // $keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
  40. // $mpdf->SetKeywords($keys);
  41. // Encrypt the file and grant permissions to the user to copy and print
  42. // No password is required to open the document
  43. // Owner has full rights using the password "MyPassword"
  44. // $mpdf->SetProtection(array('copy', 'print'), '', 'MyPassword');
  45. // $mpdf->SetProtection(array('copy', 'print', 'print-highres'), '', '');
  46. drupal_alter('print_pdf_mpdf', $mpdf, $html, $meta);
  47. $mpdf->WriteHTML($html);
  48. // try to recover from any warning/error
  49. ob_clean();
  50. return $mpdf->Output('', 'S');
  51. }