print_pdf_tcpdf.module 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @file
  4. * Generate a PDF for the print_pdf module using the TCPDF library.
  5. *
  6. * @ingroup print
  7. */
  8. define('PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT', '');
  9. define('PRINT_PDF_TCPDF_FONT_SIZE_DEFAULT', 10);
  10. define('PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT', FALSE);
  11. /**
  12. * Implements hook_pdf_tool_info().
  13. */
  14. function print_pdf_tcpdf_pdf_tool_info() {
  15. return array(
  16. 'name' => 'TCPDF',
  17. 'min_version' => '5.9.001',
  18. 'url' => 'http://sourceforge.net/projects/tcpdf/files/latest',
  19. 'expand_css' => TRUE,
  20. 'public_dirs' => array(
  21. 'cache',
  22. ),
  23. 'tool_dirs' => array(
  24. 'images',
  25. ),
  26. );
  27. }
  28. /**
  29. * Implements hook_theme().
  30. */
  31. function print_pdf_tcpdf_theme() {
  32. return array(
  33. 'print_pdf_tcpdf_header' => array(
  34. 'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
  35. 'file' => 'print_pdf_tcpdf.pages.inc',
  36. ),
  37. 'print_pdf_tcpdf_page' => array(
  38. 'variables' => array('pdf' => NULL),
  39. 'file' => 'print_pdf_tcpdf.pages.inc',
  40. ),
  41. 'print_pdf_tcpdf_content' => array(
  42. 'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
  43. 'file' => 'print_pdf_tcpdf.pages.inc',
  44. ),
  45. 'print_pdf_tcpdf_footer' => array(
  46. 'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
  47. 'file' => 'print_pdf_tcpdf.pages.inc',
  48. ),
  49. 'print_pdf_tcpdf_footer2' => array(
  50. 'variables' => array('pdf' => NULL),
  51. 'file' => 'print_pdf_tcpdf.pages.inc',
  52. ),
  53. );
  54. }
  55. /**
  56. * Implements hook_menu().
  57. */
  58. function print_pdf_tcpdf_menu() {
  59. $items = array();
  60. $items['admin/config/user-interface/print/pdf/tcpdf'] = array(
  61. 'title' => 'TCPDF',
  62. 'description' => 'Configure the TCPDF options.',
  63. 'page callback' => 'drupal_get_form',
  64. 'page arguments' => array('print_pdf_tcpdf_settings'),
  65. 'access arguments' => array('administer print'),
  66. 'type' => MENU_LOCAL_TASK,
  67. 'file' => 'print_pdf_tcpdf.admin.inc',
  68. );
  69. return $items;
  70. }
  71. /**
  72. * Implements hook_pdf_tool_version().
  73. */
  74. function print_pdf_tcpdf_pdf_tool_version($pdf_tool) {
  75. if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
  76. // Prevent TCPDF default configs.
  77. define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
  78. }
  79. if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
  80. include_once DRUPAL_ROOT . '/' . $pdf_tool;
  81. }
  82. // Hide warnings, as some TCPDF constants may still be undefined.
  83. if (class_exists('TCPDF')) {
  84. @$pdf = new TCPDF();
  85. if (class_exists('TCPDF_STATIC')) {
  86. return TCPDF_STATIC::getTCPDFVersion();
  87. }
  88. elseif (method_exists($pdf, 'getTCPDFVersion')) {
  89. return $pdf->getTCPDFVersion();
  90. }
  91. elseif (defined('PDF_PRODUCER')) {
  92. sscanf(PDF_PRODUCER, "TCPDF %s", $version);
  93. return $version;
  94. }
  95. }
  96. return 'unknown';
  97. }
  98. /**
  99. * Implements hook_print_pdf_available_libs_alter().
  100. */
  101. function print_pdf_tcpdf_print_pdf_available_libs_alter(&$pdf_tools) {
  102. module_load_include('inc', 'print', 'includes/print');
  103. $tools = _print_scan_libs('tcpdf', '!^tcpdf.php$!');
  104. foreach ($tools as $tool) {
  105. $pdf_tools['print_pdf_tcpdf|' . $tool] = 'TCPDF (' . dirname($tool) . ')';
  106. }
  107. }