I have need to send pdf via drupal mail. I want to use tcpdf library but when im trying to use example i have error: http: //..../tcpdf_example/download/simple

Fatal error: Call to a member function DrupalInitialize() on a non-object in C:\xampp\htdocs\drupalac_gw\sites\all\modules\tcpdf\tcpdf_example\tcpdf_example.pages.inc on line 55

  $html = theme('tcpdf_example_basic_html');

  // Never make an instance of TCPDF or TCPDFDrupal classes manually.
  // Use tcpdf_get_instance() instead.
  $tcpdf = tcpdf_get_instance();
  /* DrupalInitialize() is an extra method added to TCPDFDrupal that initializes
  *  some TCPDF variables (like font types), and makes possible to change the
  *  default header or footer without creating a new class.
    'footer' => array(
      'html' => 'This is a test!! <em>Bottom of the page</em>',
    'header' => array(
      'callback' => array(
        'function' => 'tcpdf_example_default_header',
        // You can pass extra data to your callback.
        'context' => array(
          'welcome_message' => 'Hello, context array!',

then somehow...

  $attachment = array(
  'filecontent' => $tcpdf->Output('', 'E');
  'filename' => 'test.txt',
  'filemime' => 'text/plain',

  switch($key) {
  case 'notice':
  $langcode = $message['language']->language;
  $message['subject'] = 'example submission from' . $account;
  $message['body'][] =''. $account .' has submitted an example.';
  $message['params']['attachments'][] = $attachment;

What i need to correct to get rid of error?

1 Answer 1


Ok First off all Installing drupal TCPDF module is not enough to have working pdf-s. We are also obligated to download TCPDF libray from http //www.tcpdf.org/ and place it to drupal files so that library will be avaible like this


above will solve:

Fatal error: Call to a member function DrupalInitialize()

With working pdf library sending emails with attachments is easy i have like this:

drupal_mail('module', 'notice', "to@mail","", array(), "from@mail");


function module_mail($key, &$message, $params) {
  $attachment = array(
    'filecontent' => generatePdf("S"),
    'filename' => 'example-filename',
    'filemime' => 'application/pdf',

  switch($key) {
    case 'notice':
      $langcode = $message['language']->language;
      $message['subject'] = 'example submission from ';
      $message['body'][] ='my example.';
      $message['params']['attachments'][] = $attachment;

And where:

function generatePdf($where="S") {
  $pdf = tcpdf_get_instance();


  // set font
  $pdf->SetFont('freeserif', '', 12);


  // set header and footer fonts
  $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

  // set default monospaced font

  // set margins

  // set auto page breaks
  $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

  // set image scale factor
  return $pdf->Output('example_008.pdf', $where);

Above is now my working example :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.