By: Olivier
Date: 2007-02-21
Time: 21:50
|
Re: Barcode
Hi,
For my own I use a TTF font library to have Barcode inside OpenOffice.
It's not specific for OpenOffice, it works with all programs, Word, Excel
To convert EAN13 code to the specific characters of the font, I use a custom function like this:
$string_ean13 = ean13_string('3400507000089');
|
And now you have to put your var in the template, and select the entire tag from [ to ] with the barcode font.
exemple of template :
Here my custom three functions to make EAN13 barcode :
/*
create a string special for this barcode TTF font library for EAN13
(string) ean13_string($s_code13)
*/
function ean13_string($s_code13)
{
$famille[0] = array('A','A','A','A','A','A');
$famille[1] = array('A','A','B','A','B','B');
$famille[2] = array('A','A','B','B','A','B');
$famille[3] = array('A','A','B','B','B','A');
$famille[4] = array('A','B','A','A','B','B');
$famille[5] = array('A','B','B','A','A','B');
$famille[6] = array('A','B','B','B','A','A');
$famille[7] = array('A','B','A','B','A','B');
$famille[8] = array('A','B','A','B','B','A');
$famille[9] = array('A','B','B','A','B','A');
$groupe['A'] = array(0 => "0", 1 => "1", 2 => "2", 3 => "3", 4 => "4", 5 => "5", 6 => "6", 7 => "7", 8 => "8", 9 => "9");
$groupe['B'] = array(0 => "G", 1 => "H", 2 => "I", 3 => "J", 4 => "K", 5 => "L", 6 => "M", 7 => "N", 8 => "O", 9 => "P");
$groupe['C'] = array(0 => "Q", 1 => "R", 2 => "S", 3 => "T", 4 => "U", 5 => "V", 6 => "W", 7 => "X", 8 => "Y", 9 => "Z");
$id_famille = (int)$s_code13[0];
$string_display = substr('abcdefghij', $id_famille, 1);
$string_display.= 'A';
for ($i=1; $i<7; $i++) {
$string_display.= $groupe[$famille[$id_famille][$i-1]][(int)$s_code13[$i]];
}
$string_display.= 'B';
for ($i=7; $i<13; $i++) {
$string_display.= $groupe['C'][(int)$s_code13[$i]];
}
$string_display.= 'A';
return $string_display;
}
/*
check if the EAN13 code is OK
(boolean) ean13_check($s_code13)
*/
function ean13_check($s_code13)
{
if (strlen($s_code13) != 13) {
return false;
}
if (ean13_compute_key(substr($s_code13, 0, 12)) == substr($s_code13, 12, 1)) {
return true;
}
return false;
}
/*
compute the key for EAN13
(string) ean13_compute_key($s_code12)
*/
function ean13_compute_key($s_code12)
{
$s_key = '';
$s_code13 = '';
if (strlen($s_code12) != 12) {
return $s_key;
}
$i = 0;
$even = 0; // pair
$odd = 0; // impair
while ($i < 12) {
$even+= (int)substr($s_code12, $i, 1);
$odd+= (int)substr($s_code12, $i+1, 1);
$i+=2;
}
$i_mod = ($even + $odd*3)%10;
$s_key = ($i_mod == 0 ? $i_mod : 10-$i_mod);
$s_code13 = $s_code12.$s_key;
return $s_key;
}
|
Now, I hear you say: "where I can find this font library ?"
Mine is commercial, I've buy a long time ago.
You'll can find one free on the net, I've see one but I lost the website. Also you have to adapt the first function 'ean13_string' to generate the good characters of your library.
Olivier
|