Contents
Login Register Wishes Forum About
Sample scripts » Tickets & Barcodes
Help topics
Latest updates
4574d  replaceImageMapTitle
4574d  replaceImageMapValues
4574d  createFunctionSerie
4574d  setAbsicssaPosition
4574d  negateValues
Toolbox
  Download as PDF
  Print this page
  Share this page
  Create an account
  Feed the updates!
Google AdSense
Creating tickets and barcodes

The pChart library can be used in various ways. It can help you to generate picture object that you‘ll then integrate into PDF files or other kind of online documents.

Sample script

The sample below will show you how to create a tag including barcodes that you can then send to a printer, attach to a mail on insert in a PDF file. You can use the pChart library from the command line to automate tasks. You can also use the crontab to schedule automatic script startup.



 /* pChart library inclusions */
 include("class/pDraw.class.php");
 include("class/pBarcode39.class.php");
 include("class/pBarcode128.class.php");
 include("class/pImage.class.php");

 /* Create the pChart object */
 $myPicture = new pImage(600,310);
 $myPicture->drawFilledRectangle(0,0,600,310,array("R"=>240,"G"=>240,"B"=>240));

 /* Draw the rounded box */
 $myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));  
 $Settings = array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0);
 $myPicture->drawRoundedFilledRectangle(10,10,590,300,10,$Settings);

 /* Draw the cell divisions */
 $myPicture->setShadow(FALSE);  
 $Settings = array("R"=>0,"G"=>0,"B"=>0);
 $myPicture->drawLine(10,110,590,110,$Settings);
 $myPicture->drawLine(200,10,200,110,$Settings);
 $myPicture->drawLine(400,10,400,110,$Settings);
 $myPicture->drawLine(10,160,590,160,$Settings);
 $myPicture->drawLine(220,160,220,200,$Settings);
 $myPicture->drawLine(320,160,320,200,$Settings);
 $myPicture->drawLine(10,200,590,200,$Settings);
 $myPicture->drawLine(400,220,400,300,$Settings);

 /* Write the fields labels */
 $myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>10)); 
 $Settings = array("R"=>0,"G"=>0,"B"=>0,"Align"=>TEXT_ALIGN_TOPLEFT);
 $myPicture->drawText(20,20,"FROM",$Settings); 
 $myPicture->drawText(210,20,"TO",$Settings); 
 $myPicture->drawText(20,120,"ACCT.\r\nNUMBER",$Settings); 
 $myPicture->drawText(20,166,"QUANTITY",$Settings); 
 $myPicture->drawText(230,166,"SHIPMENT CODE",$Settings); 
 $myPicture->drawText(330,166,"SENDER CODE",$Settings); 
 $myPicture->drawText(410,220,"MFG DATE",$Settings); 
 $myPicture->drawText(410,260,"NET WEIGTH",$Settings); 

 /* Filling the fields values */
 $myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>16)); 
 $myPicture->drawText(70,20,"BEBEER INC\r\n342, MAIN STREET\r\n33000 BORDEAUX\r\nFRANCE",$Settings); 
 $myPicture->drawText(250,20,"MUSTAFA‘S BAR\r\n18, CAPITOL STREET\r\n31000 TOULOUSE\r\nFRANCE",$Settings); 
 $myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>35)); 
 $myPicture->drawText(100,120,"2342355552340",$Settings); 
 $myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>20)); 
 $Settings = array("R"=>0,"G"=>0,"B"=>0,"Align"=>TEXT_ALIGN_TOPRIGHT);
 $myPicture->drawText(210,180,"75 CANS",$Settings); 
 $myPicture->drawText(310,180,"TLSE",$Settings); 
 $myPicture->drawText(580,180,"WAREHOUSE#SLOT#B15",$Settings); 
 $Settings = array("R"=>0,"G"=>0,"B"=>0,"Align"=>TEXT_ALIGN_TOPLEFT);
 $myPicture->drawText(410,236,"06/06/2010",$Settings); 
 $myPicture->drawText(410,276,"12.340 Kg",$Settings); 

 /* Create the barcode 39 object */ 
 $Barcode39 = new pBarcode39(); 
 $myPicture->setFontProperties(array("FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6)); 
 $Settings = array("ShowLegend"=>TRUE,"Height"=>55,"DrawArea"=>TRUE,"DrawArea"=>FALSE); 
 $Barcode39->draw($myPicture,"12250000234502",30,220,$Settings); 
 $Settings = array("ShowLegend"=>TRUE,"Height"=>14,"DrawArea"=>TRUE,"DrawArea"=>FALSE); 
 $Barcode39->draw($myPicture,"75 cans",260,220,$Settings); 
 $Barcode39->draw($myPicture,"06062010",260,260,$Settings); 

 /* Create the barcode 128 object */ 
 $Barcode128 = new pBarcode128(); 
 $Settings = array("ShowLegend"=>TRUE,"Height"=>65,"DrawArea"=>TRUE,"DrawArea"=>FALSE); 
 $Barcode128->draw($myPicture,"TLSE",450,25,$Settings); 

 /* Render the picture */
 $myPicture->Render("barcode.png");
Last updated on 06/07/2010 
by Jean-Damien 
Linked resources
Community comments
  No comments have been posted yet.
© Copyrights
Components used on this web site : Famfamfam icons has been made by Mark James, Rounded corners lite has been coded by Cameron Cooke and Tim Hutchison, SyntaxHighlighter has been written by Alex Gorbatchev. pChart and this web site have been created by Jean-Damien POGOLOTTI. This documentation contains 185 pages and 56 comments. 415 users have registered. This page has been rendered in 0,19 seconds. Wiki revision 1.37.