print_pdf.api.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the PDF version module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Provide some information on the needs of the PDF library.
  12. *
  13. * @return array
  14. * Associative array with the following data:
  15. * - name: name of the PDF library.
  16. * - min_version: minimum version of the PDF library supported by the
  17. * module.
  18. * - url: URL where the PDF library can be downloaded from.
  19. * - expand_css: boolean flag indicating whether to expand the CSS files
  20. * in the HTML passed to the PDF library, or to leave it as a list of
  21. * include directives.
  22. * - public_dirs: directories to which the tool requires write-access,
  23. * with configurable locations.
  24. * - tool_dirs: directories to which the tool requires write-access, but
  25. * can't be configured, and are relative to the tool's root path.
  26. *
  27. * @ingroup print_hooks
  28. */
  29. function hook_pdf_tool_info() {
  30. return array(
  31. 'name' => 'foopdf',
  32. 'min_version' => '1.0',
  33. 'url' => 'http://www.pdf.tool/download',
  34. 'expand_css' => FALSE,
  35. 'public_dirs' => array(
  36. 'fonts',
  37. 'cache',
  38. 'tmp',
  39. ),
  40. 'tool_dirs' => array(
  41. 'xyz',
  42. ),
  43. );
  44. }
  45. /**
  46. * Find out the version of the PDF library.
  47. *
  48. * @param string $pdf_tool
  49. * Filename of the tool to be analysed.
  50. *
  51. * @return string
  52. * version number of the library
  53. */
  54. function hook_pdf_tool_version($pdf_tool) {
  55. require_once DRUPAL_ROOT . '/' . $pdf_tool;
  56. return '1.0';
  57. }
  58. /**
  59. * Generate a PDF version of the provided HTML.
  60. *
  61. * @param string $html
  62. * HTML content of the PDF.
  63. * @param array $meta
  64. * Meta information to be used in the PDF
  65. * - url: original URL
  66. * - name: author's name
  67. * - title: Page title
  68. * - node: node object.
  69. * @param string $paper_size
  70. * (optional) Paper size of the generated PDF.
  71. * @param string $page_orientation
  72. * (optional) Page orientation of the generated PDF.
  73. *
  74. * @return Object|null
  75. * generated PDF page, or NULL in case of error
  76. *
  77. * @see print_pdf_controller_html()
  78. * @ingroup print_hooks
  79. */
  80. function hook_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
  81. $pdf = new PDF($meta, $paper_size, $page_orientation);
  82. $pdf->writeHTML($html);
  83. return $pdf->Output();
  84. }
  85. /**
  86. * Alters the list of available PDF libraries.
  87. *
  88. * During the configuration of the PDF library to be used, the module needs
  89. * to discover and display the available libraries. This function should use
  90. * the internal _print_scan_libs() function which will scan both the module
  91. * and the libraries directory in search of the unique file pattern that can
  92. * be used to identify the library location.
  93. *
  94. * @param array $pdf_tools
  95. * An associative array using as key the format 'module|path', and as value
  96. * a string describing the discovered library, where:
  97. * - module: the machine name of the module that handles this library.
  98. * - path: the path where the library is installed, relative to DRUPAL_ROOT.
  99. * If the recommended path is used, it begins with sites/all/libraries.
  100. * As a recommendation, the value should contain in parantheses the path
  101. * where the library was found, to allow the user to distinguish between
  102. * multiple install paths of the same library version.
  103. *
  104. * @ingroup print_hooks
  105. */
  106. function hook_print_pdf_available_libs_alter(&$pdf_tools) {
  107. module_load_include('inc', 'print', 'includes/print');
  108. $tools = _print_scan_libs('foo', '!^foo.php$!');
  109. foreach ($tools as $tool) {
  110. $pdf_tools['print_pdf_foo|' . $tool] = 'foo (' . dirname($tool) . ')';
  111. }
  112. }
  113. /**
  114. * Alters the PDF filename.
  115. *
  116. * Changes the value of the PDF filename variable, just before it is used to
  117. * create the file. When altering the variable, do not suffix it with the
  118. * '.pdf' extension, as the module will do that automatically.
  119. *
  120. * @param string $pdf_filename
  121. * Current value of the pdf_filename variable, after processing tokens and
  122. * any transliteration steps.
  123. * @param string $path
  124. * original alias/system path of the page being converted to PDF.
  125. *
  126. * @ingroup print_hooks
  127. */
  128. function hook_print_pdf_filename_alter(&$pdf_filename, &$path) {
  129. $pdf_filename = $path . 'foo';
  130. }
  131. /**
  132. * @} End of "addtogroup hooks".
  133. */