You are here

function tcpdf_get_instance in TCPDF 7

Same name and namespace in other branches
  1. 8 tcpdf.module \tcpdf_get_instance()

Gets an instance of TCPDFDrupal. Always use this function to get a fresh instance of the class.

Parameters

array $params: Associative array of parameters for the TCPDF constructor. Check out the documentation of TCPDF.

array $class: Associative array that tells tcpdf_get_instance to use a custom class instead of TCPDFDrupal. The class should be the sibling of TCPDFDrupal. Note that this functionality is not mature, and may be changed in later releases. 'class' => Name of the class. 'filetype' => Container file's type. 'filename' => Container file's name. 'module' => Module where the container file is.

array $config: Associative array that tells tcdf_get_instance to use a different config file. 'filetype' => Config file's type. 'filename' => Config file's name. 'module' => Module where the config file is.

Return value

mixed FALSE\TCPDFDrupal object

1 call to tcpdf_get_instance()
tcpdf_example_simple_pdf in tcpdf_example/tcpdf_example.pages.inc
Generates a pdf file using TCPDF module.

File

./tcpdf.module, line 53
TCPDF module provides an API to use TCPDF in Drupal environment.

Code

function tcpdf_get_instance($params = array(), $class = array(), $config = array()) {
  $default_params = array(
    'orientation' => 'P',
    'unit' => 'mm',
    'format' => 'A4',
    'unicode' => TRUE,
    'encoding' => 'UTF-8',
    'diskcache' => FALSE,
    'pdfa' => FALSE,
  );
  $params = array_merge($default_params, $params);
  if (!isset($class['class'])) {
    $class = array(
      'class' => 'TCPDFDrupal',
      'filetype' => 'inc',
      'filename' => 'tcpdf.class',
      'module' => 'tcpdf',
    );
  }
  if (!isset($config['filename'])) {
    $config = array(
      'filetype' => 'inc',
      'filename' => 'tcpdf.config',
      'module' => 'tcpdf',
    );
  }
  if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
    define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
    module_load_include($config['filetype'], $config['module'], $config['filename']);
  }
  if (($library = libraries_load('tcpdf')) && !empty($library['loaded'])) {
    module_load_include($class['filetype'], $class['module'], $class['filename']);
    return new $class['class']($params['orientation'], $params['unit'], $params['format'], $params['unicode'], $params['encoding'], $params['diskcache'], $params['pdfa']);
  }
  elseif (($library = libraries_detect('tcpdf')) && !empty($library['installed'])) {
    drupal_set_message(t('TCPDF library not found!'), 'error');
  }
  else {
    drupal_set_message(t('Something went wrong!'), 'error');
  }
  return FALSE;
}