I added ane function on system controller calld renderPDF(), and called the tcpdf class with the tepmlate and it works perfectly.
just call the renderPDF instead of the render function, in admin/customer,order.php -> invoice()
or in catolog/success as well, and you get the invoicr as PDF.
I used example 6 from http://www.tcpdf.org examples.
also I changed the tcpdf that I cad send the PDF file invoice as attachment.
this is the code I used:
/// -----------> add to system/controller after you put the tcpdf class in system/external/tcpdf
Code: Select all
protected function renderPDF$FileName = "invoice", $type= "I") {
/// -----> this line is from the reguler render()
$this->output = $this->fetch($this->template);
// Description : Example 006 for TCPDF class
// WriteHTML and RTL support
//
// Author: Nicola Asuni
//
// (c) Copyright:
// Nicola Asuni
// Tecnick.com s.r.l.
// Via Della Pace, 11
// 09044 Quartucciu (CA)
// ITALY
// http://www.tecnick.com
// info@tecnick.com
//============================================================+
/**
* Creates an example PDF TEST document using TCPDF
* @package com.tecnick.tcpdf
* @abstract TCPDF - Example: WriteHTML and RTL support
* @author Nicola Asuni
* @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (http://www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - http://www.tecnick.com - info@tecnick.com
* @link http://tcpdf.org
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @since 2008-03-04
*/
// instead of eng.php, set varibles from $meta var.
global $l;
$l = Array();
// PAGE META DESCRIPTORS --------------------------------------
if (($meta) && ($meta['charset'])) {
$l['a_meta_charset'] = $meta['charset'];
} else $l['a_meta_charset'] = 'UTF-8';
if (($meta) && ($meta['dir'])) {
$l['a_meta_dir'] = $meta['dir'];
} else $l['a_meta_dir'] = 'ltr';
if (($meta) && ($meta['language'])) {
$l['a_meta_language'] = $meta['language'];
} else $l['a_meta_language'] = 'eng';
// TRANSLATIONS --------------------------------------
$l['a_meta_charset'] = 'UTF-8';
$l['a_meta_language'] = 'eng';
$l['w_page'] = 'page';
//now, we don't need this line.
//require_once(DIR_SYSTEM.'external/tcpdf/config/lang/eng.php');
require_once(DIR_SYSTEM.'external/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor($this->config->get('config_store'));
$pdf->SetTitle('Save Time Store document');
$pdf->SetSubject('Invoice');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// 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 margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
if (($meta) && ($meta['dir'])) {
if (($meta['dir']=='rtl') || ($meta['dir']=='RTL')) $pdf->setLanguageArray('RTL');
if (($meta['dir']=='rtl') || ($meta['dir']=='RTL')) $pdf->setRTL(true, true);
} else {
$pdf->setLanguageArray('LTR');
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('dejavusans', '', 10);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Print a table
// add a page
$pdf->AddPage();
/// ------------ look here --------- > I put the reguler output into the PDF class <----------- look here --------
// create some HTML content
$tablecontent = $this->output;
/// ------------ look here --------- look here----------- look here --------
// output the HTML content
$pdf->writeHTML($tablecontent, true, 0, true, 0);
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
// I,D - display on screen, S - send mail, F- save as file
// $pdf->Output('invoice.pdf', 'I');
}
//============================================================+
// END OF FILE
//============================================================+
}