Background Image

Before you ask about IDnR Addon see the VirtueMart - Invoice, Delivery Note and Receipt Addon
logz05
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 06 May 2010, 12:44

Background Image

Post by logz05 »

Hi,

I am trying to radically change the format of the template of the invoice to better suit a certificate - with customer details etc.

I am trying to add in a background image to the pdf using the example on the tcpdf page:
http://www.tecnick.com/public/code/cp_d ... f_examples

precisely the example 51

Code: Select all

class MYPDF extends TCPDF {
    //Page header
    public function Header() {
        // full background image
        // store current auto-page-break status
        $bMargin = $this->getBreakMargin();
        $auto_page_break = $this->AutoPageBreak;
        $this->SetAutoPageBreak(false, 0);
        $img_file = K_PATH_IMAGES.'image_demo.jpg';
        $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
    }
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
However it goves me an error saying that the PDF_UNIT is not allowed.

Is there some way round this - is the output non standard in some way?

Thanks for your help
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48041
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Background Image

Post by Jan »

hi, no experiences with pdf_unit error :( :idea:
If you find Phoca extensions useful, please support the project
logz05
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 06 May 2010, 12:44

Re: Background Image

Post by logz05 »

Hi Jan,

I have actually solved the problem and added some extra pages and extra fields.

I am finishing it off but I will post the results for others to see in a day or two.

What I really need now is to get the invoice mailed automatically when the order is changed to shipped or at least when the invoice is generated.

N
logz05
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 06 May 2010, 12:44

Re: Background Image

Post by logz05 »

Hi,

I have succesfully used an image as a background and added extra data. This is very much what I needed for my site but can be adapated for other solutions - for example gift vouchers or gift certificates.

All the changes are made to delivery.pdf.php starting around line 350 (the end of the invoice page).

Note I am using the latest TCPDF package 5.0.004, Virtuemart 1.1.4 and J! 1.5.17

Code: Select all

// remove default header/footer
/* This gets rid of the Invoice header and footer
*  I have not found a way of re-introducing another header
*  as it can't be re-declared
*/

$pdf->setPrintHeader(false);  
$pdf->setPrintFooter(false);

//set margins
$pdf->SetMargins(10, PDF_MARGIN_TOP, 10);

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

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


/* I needed to bring in the customer name, as well as the width and length of the product*/

	$db4 = new ps_DB;
	$q = "SELECT product_id ".
		"FROM #__{vm}_order_item ".
		"WHERE order_id = ".$d['order_id'];
	$db4->query($q);
	$db4->next_record();
	$prod_id = $db4->f('product_id');
	
	$db5 = new ps_DB;
	$q = "SELECT product_length, product_width ".
		"FROM #__{vm}_product ".
		"WHERE product_id = ".$prod_id;
	$db5->query($q);
	$db5->next_record();
	$north = $db5->f('product_length');
	$west = $db5->f('product_width');


$pdf->AddPage('L', 'A4');
// set JPEG quality
$pdf->setJPEGQuality(100);

// Image example - the image needs to be in the general images folder of your Joomla instalation
$pdf->Image('../images/cert6.jpg', 10, 0, 280, 220, '', 'http://www.tcpdf.org', '', true, 150);

//To get elements in their place I use the SetX and SetY Methods

$pdf->SetX(10);
$pdf->SetFont( $pdfFont, "", 20 );
$pdf->Cell(40, 100, 'ASUNCION, '.vmFormatDate($db->f("cdate"), "%d. %B %Y"), 0, 0, 'L');
$pdf->SetX(10);
$pdf->Cell(0, 130, 'OUR EARTH SHARE S.A. CERTIFES THE OWNERSHIP OF THE PLOT', 0, 0, 'L');
$pdf->SetX(10);
$pdf->Cell(0, 145, 'LOCATED WITH SATELLITE COORDINATES', 0, 0, 'L');
$pdf->SetX(10);
$pdf->Cell(0, 160, 'NORTH '.$north.'  AND WEST '.$west. 'TO', 0, 0, 'L');
$pdf->SetX(10);
$pdf->SetFont( $pdfFont, "", 40 );
$pdf->Cell(0,200,$dbst->f("first_name") .' '. $dbst->f("middle_name").' '.$dbst->f("last_name"),0,0,'L');

//End certificate

//Start contract

$pdf->AddPage('P', 'A4');

// Resolve the country name from the country code

		$db6 = new ps_DB;
	$q = "SELECT country ".
		"FROM #__{vm}_order_user_info  ".
			"WHERE order_id = ".$d['order_id'];
	$db6->query($q);
	$db6->next_record();
	$country_cod = $db6->f('country');
	
	
	
	$country = $dbst->f("country");
	$dbc = new ps_DB;
			$dbc->query( "SELECT country_name FROM #__{vm}_country WHERE country_3_code = '$country_cod'");
			$dbc->next_record();
			$country_name = $dbc->f("country_name");

         	
	        		
		          		     
	
$cellheader='<strong>PRIVATE AGREEMENT &ndash; SALE OF REAL ESTATE <br /><br /><br /></strong>';

$cellcontent ='Being the' .vmFormatDate($db->f("cdate"), "%d. %B %Y"). '<br />ONE OF THE PARTIES, the corporation YOUR EARTH SHARE S.A. with corporate domicile in Montevideo, Uruguay, registered on the Registry of Commerce of Uruguay under the registration number 10941. 

<br /><br />THE OTHER PARTY, Mr./Ms.'.$dbst->f("first_name") .' '. $dbst->f("middle_name").' '.$dbst->f("last_name").', domiciled at '.$dbst->f("address_1") .' '. $dbst->f("address_2").' '.$dbst->f("zip").' '.$dbst->f("city").' '.$country_name.'.<br /><br />All of the appearing parties are able, and agree to execute this contract of PRIVATE UNDERTAKING OF PURCHASE AND SALE OF REAL ESTATE, which will be governed under the following clauses and conditions:

<br /><br /><strong>FIRST <br /></strong>The corporation YOUR EARTH SHARE S.A. commits and undertakes to transfer in favor of Mr. /Ms.'.$dbst->f("first_name") .' '. $dbst->f("middle_name").' '.$dbst->f("last_name").', a real estate property of their own, with everything that is built, nailed and planted, located in the district of Chaco, Paraguay, comprising the following satelite coordinates: North'.$north.' and West '. $west. '. 
.
.
.
.

<br><br><strong>EIGHTH <br /></strong>The parties submit to the jurisdiction of the ordinary courts of Asuncion, Republic of Paraguay, waiving any other jurisdiction or laws, and establish their domiciles at the places already specified herewith, at which locations will be valid and effective any type of notices formalized by the parties, the same as if they were personally made. <br />In evidence of conformity and acceptance of all the above-mentioned clauses, the parties subscribe in two copies of the same and sole tenor and effect.';


$pdf->SetMargins("10.0","10.0");
$pdf->SetFont( $pdfFont, "", 15 );
$pdf->writeHTML($cellheader, true, 0, true, 0);
$pdf->Sety(10);
$pdf->SetFont( $pdfFont, "", 11 );

$pdf->writeHTML($cellcontent, true, 0, true, 0);


$pdf->lastPage();

// End extra pages


Works for what I need......
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48041
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Background Image

Post by Jan »

Hi, thank you for sharing your code.

Jan
If you find Phoca extensions useful, please support the project
logz05
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 06 May 2010, 12:44

Re: Background Image

Post by logz05 »

Hi dpers,


Download and install Jan's Virtuemart addon (https://www.phoca.cz/download/category/2 ... art-addons)

Once installed go to administrator/components/com_virtuemart/pdf/ you will find delivery.pdf.php. There you can make the changes I indicated earlier

Hope that helps
brigittea
Phoca Newbie
Phoca Newbie
Posts: 1
Joined: 15 Feb 2011, 12:02

Re: Background Image

Post by brigittea »

Thanks so much for this post, I have been searching for some time for a way to produce vouchers, and I see this is going to suit my needs perfectly!

I have a question, is there any way of limiting when the voucher is generated? for example, I have a website which will sell products as well as vouchers, so if I modify the "invoice" and turn it into a gift voucher then obviously I don't want this to be available if the customer purchases a product!

I was considering using the "product types"built into virtuemart (I am using V1.1.6) so maybe assigning products to a "Product" type, and vouchers to a "voucher" type, then somehow (I am no coder by any long shot) telling virtuemart to only produce the vouchers if a "voucher" has been purchased?

If anyone is able to provide any assistance it would be greatly appreciated!
Post Reply