tcpdf.module in TCPDF 7
Same filename and directory in other branches
TCPDF module provides an API to use TCPDF in Drupal environment.
File
tcpdf.moduleView source
<?php
/**
* @file
* TCPDF module provides an API to use TCPDF in Drupal environment.
*/
/**
* Implements hook_libraries_info().
*/
function tcpdf_libraries_info() {
$libraries['tcpdf'] = array(
'name' => 'TCPDF',
'vendor url' => 'http://www.tcpdf.org/',
'download url' => 'https://sourceforge.net/projects/tcpdf/files/',
'version arguments' => array(
'file' => 'CHANGELOG.TXT',
'pattern' => '/([0-9\\.]+)/',
'lines' => 1,
),
'files' => array(
'php' => array(
'tcpdf.php',
),
),
);
return $libraries;
}
/**
* Gets an instance of TCPDFDrupal. Always use this function to get a fresh
* instance of the class.
*
* @param array $params
* Associative array of parameters for the TCPDF constructor. Check out the
* documentation of TCPDF.
* @param 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.
* @param 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 mixed FALSE\TCPDFDrupal object
*/
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;
}
Functions
Name | Description |
---|---|
tcpdf_get_instance | Gets an instance of TCPDFDrupal. Always use this function to get a fresh instance of the class. |
tcpdf_libraries_info | Implements hook_libraries_info(). |