You are here

print_pdf_dompdf.module in Printer, email and PDF versions 7.2

Generate a PDF for the print_pdf module using the dompdf library.

File

print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.module
View source
<?php

/**
 * @file
 * Generate a PDF for the print_pdf module using the dompdf library.
 *
 * @ingroup print
 */
define('PRINT_PDF_DOMPDF_UNICODE_DEFAULT', 0);
define('PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT', FALSE);

/**
 * Implements hook_pdf_tool_info().
 */
function print_pdf_dompdf_pdf_tool_info() {
  return array(
    'name' => 'dompdf',
    'min_version' => '0.8.2',
    'url' => 'https://github.com/dompdf/dompdf/releases/latest',
    'expand_css' => FALSE,
    'public_dirs' => array(
      'fonts',
    ),
  );
}

/**
 * Implements hook_theme().
 */
function print_pdf_dompdf_theme() {
  return array(
    'print_pdf_dompdf_footer' => array(
      'variables' => array(
        'html' => '',
      ),
      'file' => 'print_pdf_dompdf.pages.inc',
    ),
  );
}

/**
 * Implements hook_menu().
 */
function print_pdf_dompdf_menu() {
  $items = array();
  $items['admin/config/user-interface/print/pdf/dompdf'] = array(
    'title' => 'dompdf',
    'description' => 'Configure the dompdf options.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'print_pdf_dompdf_settings',
    ),
    'access arguments' => array(
      'administer print',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'print_pdf_dompdf.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_pdf_tool_version().
 */
function print_pdf_dompdf_pdf_tool_version($pdf_tool) {
  if (basename($pdf_tool) == 'Dompdf.php') {
    $dompdf_base = dirname(dirname($pdf_tool));
    $version_file = $dompdf_base . '/VERSION';
    if (file_exists($version_file)) {

      // From 0.7.0 beta 3 onwards, there's a VERSION file.
      return file_get_contents($version_file);
    }
    elseif (basename(dirname($pdf_tool)) === 'src') {

      // The dompdf tool started using PSR-4 in 0.7.0 beta 2.
      return '0.7.0 beta 2';
    }
    elseif (basename(dirname($pdf_tool)) === 'Dompdf') {

      // In 0.7.0 beta 1, it was src/Dompdf/Dompdf.php.
      return '0.7.0 beta 1';
    }
  }
  else {
    if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
      include_once DRUPAL_ROOT . '/' . $pdf_tool;
    }

    // Poor man's way to find dompdf version pre 0.7.
    if (defined('DOMPDF_ENABLE_AUTOLOAD')) {

      // It is not possible to tell apart 0.6.0, 0.6.1 or 0.6.2.
      return '0.6.0, or higher';
    }
    elseif (defined('DOMPDF_ADMIN_USERNAME')) {
      return '0.6.0 beta3';
    }
    elseif (defined('DOMPDF_LOG_OUTPUT_FILE')) {
      return '0.6.0 beta2';
    }
    elseif (defined('DOMPDF_FONT_CACHE')) {
      return '0.6.0 beta1';
    }
    elseif (defined('DOMPDF_CHROOT')) {
      return '0.5.2';
    }
    elseif (defined('DOMPDF_DIR')) {
      return '0.5.1';
    }
  }
  return 'unknown';
}

/**
 * Implements hook_print_pdf_available_libs_alter().
 */
function print_pdf_dompdf_print_pdf_available_libs_alter(&$pdf_tools) {
  module_load_include('inc', 'print', 'includes/print');
  $tools = _print_scan_libs('dompdf', '!^(dompdf_config.inc.php|Dompdf.php)$!');
  foreach ($tools as $tool) {
    if (basename($tool) == 'Dompdf.php') {
      $pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname(dirname($tool)) . ')';
    }
    else {
      $pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname($tool) . ')';
    }
  }
}

Related topics