Generate PDF and send mail 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.
  */
  $tcpdf-&gt;DrupalInitialize(array(
    'footer' =&gt; array(
      'html' =&gt; 'This is a test!! &lt;em&gt;Bottom of the page&lt;/em&gt;',
    ),
    'header' =&gt; array(
      'callback' =&gt; array(
        'function' =&gt; 'tcpdf_example_default_header',
        // You can pass extra data to your callback.
        'context' =&gt; array(
          'welcome_message' =&gt; 'Hello, context array!',
        ),
      ),
    ),
  ));


then somehow...

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

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


What i need to correct to get rid of error?
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 


  C:\xampp\htdocs\drupalac_gw\sites\all\libraries\tcpdf\tcpdf.php


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");


where:

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

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


And where:

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

  $pdf-&gt;setFontSubsetting(true);

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

  $pdf-&gt;SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 008', PDF_HEADER_STRING);

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

  // set default monospaced font
  $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

  // set margins
  $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP+10, PDF_MARGIN_RIGHT);
  $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
  $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);

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

  // set image scale factor
  $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  return $pdf-&gt;Output('example_008.pdf', $where);
}


Above is now my working example :)