You are here

function commerce_invoice_pdf_load_dompdf in Commerce Invoice 7.2

Helper function that instantiates new DOMPDF class.

Uses config functionality from Commerce Billy.

Return value

DOMPDF|\Dompdf\Dompdf|FALSE

See also

commerce_billy_pdf_prepare_dompdf()

1 call to commerce_invoice_pdf_load_dompdf()
commerce_invoice_pdf_generate in modules/pdf/commerce_invoice_pdf.module
Generate a PDF for an invoice.

File

modules/pdf/commerce_invoice_pdf.module, line 240
The Commerce Invoice PDF module.

Code

function commerce_invoice_pdf_load_dompdf() {
  $path = libraries_get_path('dompdf');
  if (!empty($path)) {
    $dir = drupal_realpath('public://');

    //@todo: Ditch these constants once DOMPDF 0.6.* support gets removed.
    if (!defined('DOMPDF_FONT_DIR')) {
      define('DOMPDF_FONT_DIR', $dir . '/fonts/');
    }
    if (!defined('DOMPDF_TEMP_DIR')) {
      define('DOMPDF_TEMP_DIR', file_directory_temp());
    }

    // Support for Dompdf 0.7.0 and newer, using PHP 5.3 namespaces.
    if (file_exists(DRUPAL_ROOT . '/' . $path . '/autoload.inc.php')) {
      require_once DRUPAL_ROOT . '/' . $path . '/autoload.inc.php';
      $dompdf = new \Dompdf\Dompdf([
        'tempDir' => DOMPDF_TEMP_DIR,
        'fontDir' => DOMPDF_FONT_DIR,
        'isHtml5ParserEnabled' => TRUE,
      ]);
      $dompdf
        ->setPaper('a4', 'portrait');
    }
    else {
      require_once DRUPAL_ROOT . '/' . $path . '/dompdf_config.inc.php';
      spl_autoload_register('DOMPDF_autoload');
      $dompdf = new DOMPDF();
      $dompdf
        ->set_paper('a4', 'portrait');
    }
    return $dompdf;
  }
  return FALSE;
}