1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Generate a PDF for the print_pdf module using the dompdf library.
|
6
|
*
|
7
|
* @ingroup print
|
8
|
*/
|
9
|
|
10
|
define('PRINT_PDF_DOMPDF_UNICODE_DEFAULT', 0);
|
11
|
define('PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT', FALSE);
|
12
|
|
13
|
/**
|
14
|
* Implements hook_pdf_tool_info().
|
15
|
*/
|
16
|
function print_pdf_dompdf_pdf_tool_info() {
|
17
|
return array(
|
18
|
'name' => 'dompdf',
|
19
|
'url' => 'https://github.com/dompdf/dompdf/releases/latest',
|
20
|
'expand_css' => FALSE,
|
21
|
'public_dirs' => array(
|
22
|
'fonts',
|
23
|
),
|
24
|
);
|
25
|
}
|
26
|
|
27
|
/**
|
28
|
* Implements hook_theme().
|
29
|
*/
|
30
|
function print_pdf_dompdf_theme() {
|
31
|
return array(
|
32
|
'print_pdf_dompdf_footer' => array(
|
33
|
'variables' => array('html' => ''),
|
34
|
'file' => 'print_pdf_dompdf.pages.inc',
|
35
|
),
|
36
|
);
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* Implements hook_menu().
|
41
|
*/
|
42
|
function print_pdf_dompdf_menu() {
|
43
|
$items = array();
|
44
|
|
45
|
$items['admin/config/user-interface/print/pdf/dompdf'] = array(
|
46
|
'title' => 'dompdf',
|
47
|
'description' => 'Configure the dompdf options.',
|
48
|
'page callback' => 'drupal_get_form',
|
49
|
'page arguments' => array('print_pdf_dompdf_settings'),
|
50
|
'access arguments' => array('administer print'),
|
51
|
'type' => MENU_LOCAL_TASK,
|
52
|
'file' => 'print_pdf_dompdf.admin.inc',
|
53
|
);
|
54
|
|
55
|
return $items;
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Implements hook_pdf_tool_version().
|
60
|
*/
|
61
|
function print_pdf_dompdf_pdf_tool_version($pdf_tool) {
|
62
|
if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
|
63
|
include_once DRUPAL_ROOT . '/' . $pdf_tool;
|
64
|
}
|
65
|
|
66
|
if (basename($pdf_tool) == 'Dompdf.php') {
|
67
|
$dompdf_base = dirname(dirname($pdf_tool));
|
68
|
$version_file = $dompdf_base . '/VERSION';
|
69
|
if (file_exists($version_file)) {
|
70
|
// From 0.7.0 beta 3 onwards, there's a VERSION file.
|
71
|
return file_get_contents($version_file);
|
72
|
}
|
73
|
elseif (basename(dirname($pdf_tool)) === 'src') {
|
74
|
// The dompdf tool started using PSR-4 in 0.7.0 beta 2.
|
75
|
return '0.7.0 beta 2';
|
76
|
}
|
77
|
elseif (basename(dirname($pdf_tool)) === 'Dompdf') {
|
78
|
// In 0.7.0 beta 1, it was src/Dompdf/Dompdf.php.
|
79
|
return '0.7.0 beta 1';
|
80
|
}
|
81
|
}
|
82
|
else {
|
83
|
// Poor man's way to find dompdf version pre 0.7.
|
84
|
if (defined('DOMPDF_ENABLE_AUTOLOAD')) {
|
85
|
// It is not possible to tell apart 0.6.0, 0.6.1 or 0.6.2.
|
86
|
return '0.6.0, or higher';
|
87
|
}
|
88
|
elseif (defined('DOMPDF_ADMIN_USERNAME')) {
|
89
|
return '0.6.0 beta3';
|
90
|
}
|
91
|
elseif (defined('DOMPDF_LOG_OUTPUT_FILE')) {
|
92
|
return '0.6.0 beta2';
|
93
|
}
|
94
|
elseif (defined('DOMPDF_FONT_CACHE')) {
|
95
|
return '0.6.0 beta1';
|
96
|
}
|
97
|
elseif (defined('DOMPDF_CHROOT')) {
|
98
|
return '0.5.2';
|
99
|
}
|
100
|
elseif (defined('DOMPDF_DIR')) {
|
101
|
return '0.5.1';
|
102
|
}
|
103
|
}
|
104
|
return 'unknown';
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* Implements hook_print_pdf_available_libs_alter().
|
109
|
*/
|
110
|
function print_pdf_dompdf_print_pdf_available_libs_alter(&$pdf_tools) {
|
111
|
module_load_include('inc', 'print', 'includes/print');
|
112
|
$tools = _print_scan_libs('dompdf', '!^(dompdf_config.inc.php|Dompdf.php)$!');
|
113
|
|
114
|
foreach ($tools as $tool) {
|
115
|
if (basename($tool) == 'Dompdf.php') {
|
116
|
$pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname(dirname($tool)) . ')';
|
117
|
}
|
118
|
else {
|
119
|
$pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname($tool) . ')';
|
120
|
}
|
121
|
}
|
122
|
}
|