Project

General

Profile

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

root / drupal7 / sites / all / modules / print / print_pdf / print_pdf.api.php @ 76bdcd04

1
<?php
2

    
3
/**
4
 * @file
5
 * Hooks provided by the PDF version module.
6
 */
7

    
8
/**
9
 * @addtogroup hooks
10
 * @{
11
 */
12

    
13
/**
14
 * Provide some information on the needs of the PDF library.
15
 *
16
 * @return array
17
 *   Associative array with the following data:
18
 *   - name: name of the PDF library.
19
 *   - min_version: minimum version of the PDF library supported by the
20
 *     module.
21
 *   - url: URL where the PDF library can be downloaded from.
22
 *   - expand_css: boolean flag indicating whether to expand the CSS files
23
 *     in the HTML passed to the PDF library, or to leave it as a list of
24
 *     include directives.
25
 *   - public_dirs: directories to which the tool requires write-access,
26
 *     with configurable locations.
27
 *   - tool_dirs: directories to which the tool requires write-access, but
28
 *     can't be configured, and are relative to the tool's root path.
29
 *
30
 * @ingroup print_hooks
31
 */
32
function hook_pdf_tool_info() {
33
  return array(
34
    'name' => 'foopdf',
35
    'min_version' => '1.0',
36
    'url' => 'http://www.pdf.tool/download',
37
    'expand_css' => FALSE,
38
    'public_dirs' => array(
39
      'fonts',
40
      'cache',
41
      'tmp',
42
    ),
43
    'tool_dirs' => array(
44
      'xyz',
45
    ),
46
  );
47
}
48

    
49
/**
50
 * Find out the version of the PDF library.
51
 *
52
 * @param string $pdf_tool
53
 *   Filename of the tool to be analysed.
54
 *
55
 * @return string
56
 *   version number of the library
57
 */
58
function hook_pdf_tool_version($pdf_tool) {
59
  require_once DRUPAL_ROOT . '/' . $pdf_tool;
60

    
61
  return '1.0';
62
}
63

    
64
/**
65
 * Generate a PDF version of the provided HTML.
66
 *
67
 * @param string $html
68
 *   HTML content of the PDF.
69
 * @param array $meta
70
 *   Meta information to be used in the PDF
71
 *   - url: original URL
72
 *   - name: author's name
73
 *   - title: Page title
74
 *   - node: node object.
75
 * @param string $paper_size
76
 *   (optional) Paper size of the generated PDF.
77
 * @param string $page_orientation
78
 *   (optional) Page orientation of the generated PDF.
79
 *
80
 * @return Object|null
81
 *   generated PDF page, or NULL in case of error
82
 *
83
 * @see print_pdf_controller_html()
84
 * @ingroup print_hooks
85
 */
86
function hook_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
87
  $pdf = new PDF($meta, $paper_size, $page_orientation);
88
  $pdf->writeHTML($html);
89

    
90
  return $pdf->Output();
91
}
92

    
93
/**
94
 * Alters the list of available PDF libraries.
95
 *
96
 * During the configuration of the PDF library to be used, the module needs
97
 * to discover and display the available libraries. This function should use
98
 * the internal _print_scan_libs() function which will scan both the module
99
 * and the libraries directory in search of the unique file pattern that can
100
 * be used to identify the library location.
101
 *
102
 * @param array $pdf_tools
103
 *   An associative array using as key the format 'module|path', and as value
104
 *   a string describing the discovered library, where:
105
 *   - module: the machine name of the module that handles this library.
106
 *   - path: the path where the library is installed, relative to DRUPAL_ROOT.
107
 *     If the recommended path is used, it begins with sites/all/libraries.
108
 *   As a recommendation, the value should contain in parantheses the path
109
 *   where the library was found, to allow the user to distinguish between
110
 *   multiple install paths of the same library version.
111
 *
112
 * @ingroup print_hooks
113
 */
114
function hook_print_pdf_available_libs_alter(&$pdf_tools) {
115
  module_load_include('inc', 'print', 'includes/print');
116
  $tools = _print_scan_libs('foo', '!^foo.php$!');
117

    
118
  foreach ($tools as $tool) {
119
    $pdf_tools['print_pdf_foo|' . $tool] = 'foo (' . dirname($tool) . ')';
120
  }
121
}
122

    
123
/**
124
 * Alters the PDF filename.
125
 *
126
 * Changes the value of the PDF filename variable, just before it is used to
127
 * create the file. When altering the variable, do not suffix it with the
128
 * '.pdf' extension, as the module will do that automatically.
129
 *
130
 * @param string $pdf_filename
131
 *   Current value of the pdf_filename variable, after processing tokens and
132
 *   any transliteration steps.
133
 * @param string $path
134
 *   original alias/system path of the page being converted to PDF.
135
 *
136
 * @ingroup print_hooks
137
 */
138
function hook_print_pdf_filename_alter(&$pdf_filename, &$path) {
139
  $pdf_filename = $path . 'foo';
140
}
141

    
142
/**
143
 * @} End of "addtogroup hooks".
144
 */