Hi i've created 3 functions to show barcodes EAN8 and EAN13 with addon of 2/5 numbers if needed
You must use the font that i've attached
EAN8(code,7) generates an barcode string that can be showed using "Code EAN" FontPHP Code:function EAN8(chaine)
if String.Length(chaine) == 7 then
checksum="";
min = 7;
max = 1;
step = -2;
for count = min, max, step do
checksum=String.ToNumber(checksum)+String.ToNumber(String.Mid(chaine, count, 1));
end
checksum=checksum*3
min = 6;
max = 1;
step = -2;
for count = min, max, step do
checksum=String.ToNumber(checksum)+String.Mid(String.ToNumber(chaine), count, 1);
end
k1=Math.Mod(checksum,10)
chaine=chaine..Math.Mod(10-k1,10)
codebarre=":"
min = 1;
max = 4;
for count = min, max do
codebarre=codebarre..String.Char(65+String.Mid(chaine, count, 1));
end
codebarre=codebarre.."*"
min = 5;
max = 8;
for count = min, max do
codebarre=codebarre..String.Char(97+String.Mid(chaine, count, 1));
end
codebarre=codebarre.."+"
end
return codebarre
end
function EAN13(chaine)
if String.Length(chaine)==12 then
min = 12;
max = 1;
step = -2;
checksum=""
for count = min, max, step do
checksum=String.ToNumber(checksum)+String.ToNumber(String.Mid(chaine, count, 1));
end
checksum=checksum*3
min = 11;
max = 1;
step = -2;
for count = min, max, step do
checksum=String.ToNumber(checksum)+String.ToNumber(String.Mid(chaine, count, 1));
end
k1=Math.Mod(checksum,10)
chaine=chaine..Math.Mod(10-k1,10)
codebarre=String.Left(chaine, 1)..String.Char(65+String.Mid(chaine, 2, 1))
end
first= String.ToNumber(String.Left(chaine, 1));
min = 3;
max = 7;
for count = min, max do
tablea=false
if (count==3) then
if (first==0 or first==1 or first==2 or first==3) then
tablea=true
end
elseif (count==4) then
if (first==0 or first==4 or first==7 or first==8) then
tablea=true
end
elseif (count==5) then
if (first==0 or first==1 or first==4 or first==5 or first==9) then
tablea=true
end
elseif (count==6) then
if (first==0 or first==2 or first==5 or first==6 or first==7) then
tablea=true
end
elseif (count==7) then
if (first==0 or first==3 or first==6 or first==9) then
tablea=true
end
end
if (tablea==true) then
codebarre=codebarre..String.Char(65+String.Mid(chaine, count, 1));
else
codebarre=codebarre..String.Char(75+String.Mid(chaine, count, 1));
end
end
codebarre=codebarre.."*"
min = 8;
max = 13;
for count = min, max do
codebarre=codebarre..String.Char(97+String.Mid(chaine, count, 1));
end
codebarre=codebarre.."+"
return codebarre
end
function ADDON(chaine)
if String.Length(chaine)==2 or String.Length(chaine)==5 then
checksum=""
if String.Length(chaine)==2 then
checksum=10+Math.Mod(chaine,4);
else
min = 1;
max = 5;
step = 2;
for count = min, max, step do
checksum=String.ToNumber(checksum)+String.ToNumber(String.Mid(chaine, count, 1));
end
checksum=Math.Mod(checksum*3+(String.Mid(chaine, 2, 1)*9)+(String.Mid(chaine, 4, 1)*9),10)
end
addon="["
min = 1;
max = String.Length(chaine);
for count = min, max do
tablea=false;
if (count==1) then
if (checksum==4 or checksum==5 or checksum==6 or checksum==7 or checksum==8 or checksum==9 or checksum==10 or checksum==11) then
tablea=true
end
elseif (count==2) then
if (checksum==1 or checksum==2 or checksum==3 or checksum==5 or checksum==6 or checksum==9 or checksum==10 or checksum==12) then
tablea=true
end
elseif (count==3) then
if (checksum==0 or checksum==2 or checksum==3 or checksum==6 or checksum==7 or checksum==8) then
tablea=true
end
elseif (count==4) then
if (checksum==0 or checksum==1 or checksum==3 or checksum==4 or checksum==8 or checksum==9) then
tablea=true
end
elseif (count==5) then
if (checksum==0 or checksum==1 or checksum==2 or checksum==4 or checksum==5 or checksum==7) then
tablea=true
end
end
if (tablea==true) then
addon=addon..String.Char(65+String.Mid(chaine,count,1))
else
addon=addon..String.Char(75+String.Mid(chaine,count,1))
end
if (String.Length(chaine)==2 and count==1) or (String.Length(chaine)==5 and count<5) then
addon=addon..String.Char(92)
end
end
end
return addon
end
EAN13(code,12) generates an barcode string that can be showed using "Code EAN" Font
ADDON(code,2/5) generates an addon for barcode string that can be showed using "Code EAN" Font
I've created a simple app to work with it, tomorrow i will share it (i've created in spanish)
![]()

Reply With Quote