1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Generate a PDF for the print_pdf module using the mPDF library.
|
6
|
*
|
7
|
* @ingroup print
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Implements hook_pdf_tool_info().
|
12
|
*/
|
13
|
function print_pdf_mpdf_pdf_tool_info() {
|
14
|
$info = array(
|
15
|
'name' => 'mPDF',
|
16
|
'url' => 'https://github.com/mpdf/mpdf/releases/latest',
|
17
|
'expand_css' => FALSE,
|
18
|
'public_dirs' => array(
|
19
|
'ttfontdata',
|
20
|
'tmp',
|
21
|
),
|
22
|
);
|
23
|
|
24
|
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
|
25
|
if (!isset($pdf_tool[1]) || print_pdf_mpdf_pdf_tool_version($pdf_tool[1]) !== '>= 7.x') {
|
26
|
$info['tool_dirs'] = array(
|
27
|
'graph_cache',
|
28
|
);
|
29
|
}
|
30
|
return $info;
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* Implements hook_pdf_tool_version().
|
35
|
*/
|
36
|
function print_pdf_mpdf_pdf_tool_version($pdf_tool) {
|
37
|
if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
|
38
|
include_once DRUPAL_ROOT . '/' . $pdf_tool;
|
39
|
}
|
40
|
|
41
|
if (defined('mPDF_VERSION')) {
|
42
|
return mPDF_VERSION;
|
43
|
}
|
44
|
else {
|
45
|
// Version 7 of the mpdf library uses a composer autoloader.
|
46
|
// Also there no longer is a way to truly detect the library version, so
|
47
|
// this seems like the best alternative.
|
48
|
$mpdf_version_7_plus = strpos($pdf_tool, 'autoload.php') !== FALSE;
|
49
|
if ($mpdf_version_7_plus) {
|
50
|
return '>= 7.x';
|
51
|
}
|
52
|
else {
|
53
|
return 'unknown';
|
54
|
}
|
55
|
}
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Implements hook_print_pdf_available_libs_alter().
|
60
|
*/
|
61
|
function print_pdf_mpdf_print_pdf_available_libs_alter(&$pdf_tools) {
|
62
|
module_load_include('inc', 'print', 'includes/print');
|
63
|
$tools = _print_scan_libs('mpdf', '!^mpdf.php$!');
|
64
|
|
65
|
foreach ($tools as $tool) {
|
66
|
$pdf_tools['print_pdf_mpdf|' . $tool] = 'mPDF (' . dirname($tool) . ')';
|
67
|
}
|
68
|
|
69
|
// mPDF >= 7.0 uses a composer autoloader.
|
70
|
$tools = _print_scan_libs('mpdf', '!^autoload.php$!');
|
71
|
foreach ($tools as $tool) {
|
72
|
if (preg_match('!mpdf.*?/vendor/autoload.php$!', $tool)) {
|
73
|
$pdf_tools['print_pdf_mpdf|' . $tool] = 'mPDF (' . dirname(dirname($tool)) . ')';
|
74
|
}
|
75
|
}
|
76
|
}
|