You are here

function _print_pdf_tcpdf in Printer, email and PDF versions 5.3

Same name and namespace in other branches
  1. 5.4 print_pdf/print_pdf.pages.inc \_print_pdf_tcpdf()
  2. 6 print_pdf/print_pdf.pages.inc \_print_pdf_tcpdf()
  3. 7 print_pdf/print_pdf.pages.inc \_print_pdf_tcpdf()
  4. 5.x print_pdf/print_pdf.pages.inc \_print_pdf_tcpdf()

Generate the PDF file using the TCPDF library

Parameters

$print: array containing the configured data

$html: contents of the post-processed template already with the node data

$filename: name of the PDF file to be generated

See also

print_pdf_controller()

1 call to _print_pdf_tcpdf()
print_pdf_controller in print_pdf/print_pdf.pages.inc
Generate a PDF version of the printer-friendly page

File

print_pdf/print_pdf.pages.inc, line 120

Code

function _print_pdf_tcpdf($print, $html, $filename) {
  global $base_url;
  $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
  $print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
  $print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
  $print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
  $pdf_tool_path = realpath(dirname($print_pdf_pdf_tool));
  define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
  define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
  define('K_PATH_URL', $base_url);
  define('K_PATH_FONTS', $pdf_tool_path . '/fonts/');
  define('K_PATH_CACHE', $pdf_tool_path . '/cache/');
  define('K_PATH_IMAGES', '');
  define('K_BLANK_IMAGE', $pdf_tool_path . '/images/_blank.png');
  define('K_CELL_HEIGHT_RATIO', 1.25);
  define('K_SMALL_RATIO', 2 / 3);
  require_once $print_pdf_pdf_tool;
  if (strpos(PDF_PRODUCER, 'PHP4') === FALSE) {
    require_once drupal_get_path('module', 'print_pdf') . '/print_pdf.class.inc';
  }
  else {
    require_once drupal_get_path('module', 'print_pdf') . '/print_pdf.class_php4.inc';
  }
  $font = array(
    variable_get('print_pdf_font_family', PRINT_PDF_FONT_FAMILY_DEFAULT),
    '',
    variable_get('print_pdf_font_size', PRINT_PDF_FONT_SIZE_DEFAULT),
  );
  $orientation = drupal_strtoupper($print_pdf_page_orientation[0]);

  // create new PDF document
  $pdf = new PrintTCPDF($orientation, 'mm', $print_pdf_paper_size, TRUE);

  // set document information
  $pdf
    ->SetAuthor(strip_tags($print['submitted']));
  $pdf
    ->SetCreator(variable_get('site_name', 'Drupal'));
  $pdf
    ->SetTitle($print['title']);
  $keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
  $pdf
    ->SetKeywords($keys);
  $pdf
    ->setPDFVersion('1.6');
  $pdf = theme('print_pdf_tcpdf_header', $pdf, $html, $font);
  $pdf = theme('print_pdf_tcpdf_footer', $pdf, $html, $font);
  $pdf = theme('print_pdf_tcpdf_page', $pdf);

  //initialize document
  $pdf
    ->AliasNbPages();

  // add a page
  $pdf
    ->AddPage();
  $pdf = theme('print_pdf_tcpdf_content', $pdf, $html, $font);

  // reset pointer to the last page
  $pdf
    ->lastPage();

  //Close and output PDF document
  $output_dest = $print_pdf_content_disposition == 2 ? 'D' : 'I';
  $pdf
    ->Output($filename, $output_dest);
}