Project

General

Profile

Paste
Download (3.1 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / print / print_pdf / lib_handlers / print_pdf_tcpdf / print_pdf_tcpdf.module @ 76bdcd04

1
<?php
2

    
3
/**
4
 * @file
5
 * Generate a PDF for the print_pdf module using the TCPDF library.
6
 *
7
 * @ingroup print
8
 */
9

    
10
define('PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT', '');
11
define('PRINT_PDF_TCPDF_FONT_SIZE_DEFAULT', 10);
12
define('PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT', FALSE);
13

    
14
/**
15
 * Implements hook_pdf_tool_info().
16
 */
17
function print_pdf_tcpdf_pdf_tool_info() {
18
  return array(
19
    'name' => 'TCPDF',
20
    'min_version' => '5.9.001',
21
    'url' => 'http://sourceforge.net/projects/tcpdf/files/latest',
22
    'expand_css' => TRUE,
23
    'public_dirs' => array(
24
      'cache',
25
    ),
26
    'tool_dirs' => array(
27
      'images',
28
    ),
29
  );
30
}
31

    
32
/**
33
 * Implements hook_theme().
34
 */
35
function print_pdf_tcpdf_theme() {
36
  return array(
37
    'print_pdf_tcpdf_header' => array(
38
      'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
39
      'file' => 'print_pdf_tcpdf.pages.inc',
40
    ),
41
    'print_pdf_tcpdf_page' => array(
42
      'variables' => array('pdf' => NULL),
43
      'file' => 'print_pdf_tcpdf.pages.inc',
44
    ),
45
    'print_pdf_tcpdf_content' => array(
46
      'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
47
      'file' => 'print_pdf_tcpdf.pages.inc',
48
    ),
49
    'print_pdf_tcpdf_footer' => array(
50
      'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
51
      'file' => 'print_pdf_tcpdf.pages.inc',
52
    ),
53
    'print_pdf_tcpdf_footer2' => array(
54
      'variables' => array('pdf' => NULL),
55
      'file' => 'print_pdf_tcpdf.pages.inc',
56
    ),
57
  );
58
}
59

    
60
/**
61
 * Implements hook_menu().
62
 */
63
function print_pdf_tcpdf_menu() {
64
  $items = array();
65

    
66
  $items['admin/config/user-interface/print/pdf/tcpdf'] = array(
67
    'title' => 'TCPDF',
68
    'description' => 'Configure the TCPDF options.',
69
    'page callback' => 'drupal_get_form',
70
    'page arguments' => array('print_pdf_tcpdf_settings'),
71
    'access arguments'  => array('administer print'),
72
    'type' => MENU_LOCAL_TASK,
73
    'file' => 'print_pdf_tcpdf.admin.inc',
74
  );
75

    
76
  return $items;
77
}
78

    
79
/**
80
 * Implements hook_pdf_tool_version().
81
 */
82
function print_pdf_tcpdf_pdf_tool_version($pdf_tool) {
83
  if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
84
    // Prevent TCPDF default configs.
85
    define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
86
  }
87
  if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
88
    include_once DRUPAL_ROOT . '/' . $pdf_tool;
89
  }
90

    
91
  // Hide warnings, as some TCPDF constants may still be undefined.
92
  if (class_exists('TCPDF')) {
93
    @$pdf = new TCPDF();
94

    
95
    if (class_exists('TCPDF_STATIC')) {
96
      return TCPDF_STATIC::getTCPDFVersion();
97
    }
98
    elseif (method_exists($pdf, 'getTCPDFVersion')) {
99
      return $pdf->getTCPDFVersion();
100
    }
101
    elseif (defined('PDF_PRODUCER')) {
102
      sscanf(PDF_PRODUCER, "TCPDF %s", $version);
103

    
104
      return $version;
105
    }
106
  }
107
  return 'unknown';
108
}
109

    
110
/**
111
 * Implements hook_print_pdf_available_libs_alter().
112
 */
113
function print_pdf_tcpdf_print_pdf_available_libs_alter(&$pdf_tools) {
114
  module_load_include('inc', 'print', 'includes/print');
115
  $tools = _print_scan_libs('tcpdf', '!^tcpdf.php$!');
116

    
117
  foreach ($tools as $tool) {
118
    $pdf_tools['print_pdf_tcpdf|' . $tool] = 'TCPDF (' . dirname($tool) . ')';
119
  }
120
}