Post by mondy » Tue Jan 05, 2010 6:55 am

b"h

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                                                 
				//============================================================+
	}
Last edited by i2Paq on Thu Jan 14, 2010 4:25 pm, edited 1 time in total.
Reason: code-tags

New member

Posts

Joined
Tue Nov 11, 2008 8:01 am

Post by max2000 » Wed Jan 06, 2010 8:48 am

which version is this for?

what are the instructions fully to add it to 1.3.4?

thanks in advance!!!

-max

Newbie

Posts

Joined
Wed Jan 06, 2010 8:48 am

Post by mondy » Wed Jan 13, 2010 11:14 pm

b"h

More details how to set PDF invoice:

( I'm using opencart 1.3.2)

1.) download the zip file from tcpdf class from http://www.tcpdf.org (http://sourceforge.net/projects/tcpdf/files/), 2.) unzip it in youre pc. you will get a tcpdf dircetory
3.) upload the tcpdf directory to youre server (I did it under www/system/external).
4.) change youre www/system/engine/controller.php and add protected function renderPDF (see above section 1 )
5.) change youre www/admin/controller/customer/order.php. go to the end of invoice() function, change the line instead of the old render ($this->render();) write : $this->renderPDF();
6.) go to youre admin panel, customer->order->edit->invoice, you will get it as PDF file
7.) change the parameters of tcpdf class to set youre logo etc.

Explanation:
a.) The tcpdf is geting a HTML table, and convert it to PDF.
b.) in www/system/engine/controller.php we are calling the tcpdf class, and puting into it the HTML table. see lines:

Code: Select all


				// create some HTML content
				$tablecontent = $this->output;

				// output the HTML content
				$pdf->writeHTML($tablecontent, true, 0, true, 0);
c.) in www/admin/controller/customer/order.php we are sending the output as pdf instaed of plain HTML

Hope. it will help you.

Code: Select all

------> section 1: ----> www/system/engine/controller.php ---> adding function fenderPDF 

	protected function renderPDF($filename = "invoice", $type= "I") {
				
		$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
				 */

				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('Nicola Asuni');
				$pdf->SetTitle('TCPDF Example 006');
				$pdf->SetSubject('TCPDF Tutorial');
				$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
				$pdf->setLanguageArray($l); 

				// ---------------------------------------------------------

				// set font
				$pdf->SetFont('dejavusans', '', 10);


				// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


				// Print a table

				// add a page
				$pdf->AddPage();

				// create some HTML content

				$tablecontent = $this->output;

				// 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                                                 
				//============================================================+
	}

---> end section 1

New member

Posts

Joined
Tue Nov 11, 2008 8:01 am

User avatar
Active Member

Posts

Joined
Fri Nov 27, 2009 3:40 pm
Location - Bangkok - Thailand

Post by i2Paq » Thu Jan 14, 2010 4:30 pm

Please us code-tags when posting codes.

I've adjusted your replys ;)

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by Miguelito » Fri Jan 15, 2010 8:07 am

Hi! Has anyone used this mod? What about adding barcode to the end of the pdf page?

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."


Active Member

Posts

Joined
Sun Jan 10, 2010 10:11 pm

Post by exactweb » Mon Nov 18, 2013 3:51 pm

Creating html then converting it to pdf is just crazy. Just call the write cell methods individually.

New member

Posts

Joined
Tue May 31, 2011 5:06 pm
Who is online

Users browsing this forum: No registered users and 2 guests