EAN 8/13 Code 39/128 Barcode Creator
12th July 2010
A couple of weeks ago I saw this post on Mibuso. This got my attention because this solution to make barcodes required no extra hassle with external components or fonts. A BMP containing the barcode is made using OutStreams, pretty neat stuff!
So I’ve started to use this piece of code to make barcodes of the type EAN8, EAN13, Code 128 & Code 39. In brief, all barcodes that I’ve already used in my (short) career.
A test with my mobile phone (Android
) and a handheld scanner quickly learned me that the barcodes were readable. At this point I decided to upload my code to Mibuso, and like this my first personal download on Mibuso is a fact!
Many thanks to Igor Pchelnikov for his initial post on Mibuso and the help he offered me to achieve this!
You can find the source code here: http://mibuso.com/dlinfo.asp?FileID=1192
All comments are off course more than welcome, this also counts for ratings.
July 21st, 2010 at 09:37
Hi lyot,
I also had the requirement to produce barcodes on NAV. And your solution is great!!
I have used this solution too http://mibuso.com/dlinfo.asp?FileID=1043
but I had to produce Code128-Barcodes as well.
I recognized a few problems when using your code: when initialising the table for Code128-encoding there is missing the entry for the value 66.
I also got a problem when trying to read the produced barcode: there was an error in calculating the WeightSum. My barcode only exitst of numbers (e.g. 1000910736) and the WeightSum and hence the CheckDigit have been wrong.
Perhaps you can have a look at these two things.
Best regards
Thomas
July 21st, 2010 at 09:59
Sure thing!
July 22nd, 2010 at 22:00
Version v1.1:
- Missing Code128 for value 66
- Bugfix in checksum calculation for Code 128
July 27th, 2010 at 13:45
Fix size (DPI), so it is very fast to scale up/down the picture
In function CreateBMPHeader add code to start
PS := ROUND(2835 / pintSize,1,’=');
pintSize := 1;
And change code
From:
poutBmpHeader.WRITE(2835, 4); //HORIZONTAL RESOLUTION
poutBmpHeader.WRITE(2835, 4); //VERTICAL RESOLUTION
To:
poutBmpHeader.WRITE(PS, 4); //HORIZONTAL RESOLUTION
poutBmpHeader.WRITE(PS, 4); //VERTICAL RESOLUTION
July 27th, 2010 at 14:22
Yep, had some troubles with scaling up the picture & performance.
I will try your solution for a next release.
Thanks for the tip!
August 11th, 2010 at 16:24
Hello, i would like to thank you, your code works great. While testing i believe i found an error with the encoding for precTmpCode128.CharC := ‘84′;
//precTmpCode128.Encoding := ‘10111100100′;
precTmpCode128.Encoding := ‘10011110100′;
Best regards
August 12th, 2010 at 07:37
Thanx for reporting the bug!
I’ll try to bring out an update this weekend.
August 16th, 2010 at 12:41
v1.2 :
- Wrong Code128 for value 84
- Performance fix for scaling barcode
September 6th, 2010 at 14:41
Hallo,
Thank you for your source. The EAN13 code we use have 13 characters so I cut the last one to use it in your function EncodeEAN13 (I believe the last one is the checksum). That works for numbers like 4260061920112. I get a barcode that I can scan en it return the same number. When I use a number like 8710871087995 it prints a barcode witch I cant scan any more. Can you tell me what do I wrong.
Lex
September 7th, 2010 at 07:32
Hi Lex,
You’re doing nothing wrong, this probably an encoding bug.
I’ll try to fix this this weekend.
This new version will also enable to print bar codes vertical.
September 7th, 2010 at 11:21
Thank you for your reply.
I wait for the new version for testing.
Lex
September 16th, 2010 at 19:06
Version v1.3 :
- Printing of vertical barcodes
- Bugfix EAN13 EAN character set encoding table
September 24th, 2010 at 08:17
Thanks, works now….
Lex
November 11th, 2010 at 10:06
Hello,
When I am trying to encode Item No. with space character in it, for example: “09P SCREW M12″ I get error message: “Code 128/39 CharA ” does not exist”. Items without spaces are working fine.
Any Idea, how to solve this problem?
Thank you,
Igor
November 11th, 2010 at 13:24
Hi Igor,
I’m gonna try to look at this, this weekend.
November 14th, 2010 at 12:00
Version v1.4 :
- Bugfix for encoding ‘.’ & ‘ ‘ in Code128
November 22nd, 2010 at 07:32
What is in your Dynamics NAV toolbelt? Barcode Creator by Stijn Bossuyt…
Stijn Bossuyt has made a great function/codeunit for generating barcodes within Dynamics NAV without…
February 8th, 2011 at 09:29
Version v1.5:
- Bugfix for encoding multiple consecutive whitespaces in Code128
August 18th, 2011 at 11:00
Since i had performance drops (not a lot but noticable) i did some changes to your code.
In the Function CreateBarcodeDetail (Horizontal):
// For Better Performance, write a String for one line!
BinaryStringLen := bxtBarcodeBinary.LENGTH;
IF BinaryStringLen <= MAXSTRLEN(BinaryString) THEN BEGIN
FOR lintBarLoop := 1 TO bxtBarcodeBinary.LENGTH DO BEGIN
bxtBarcodeBinary.GETSUBTEXT(ltxtByte,lintBarLoop,1);
IF ltxtByte = ‘1′ THEN
lchar := 0
ELSE
lchar := 255;
FOR lintSize := 1 TO pintSize DO BEGIN
//Putting Pixel: Black or White
BinaryString += FORMAT(lchar);
BinaryString += FORMAT(lchar);
BinaryString += FORMAT(lchar);
END
END;
FOR lintChainFiller := 1 TO ((lintBarLoop* pintSize) MOD 4) DO BEGIN
//Adding 0 bytes if needed - line end
lchar := 0;
BinaryString += FORMAT(lchar);
END;
FOR lintLineLoop := 1 TO pintLines * pintSize DO BEGIN
poutBmpHeader.WRITETEXT(BinaryString);
END;
END ELSE BEGIN // Slow Variant but allowes more than 1024 Bites per Line
- I simply write everything in a string of 1024 lenth. My largest EAN128 Barcode only used 299 of it so it should cover most the barcodes i guess. Otherwise we could make the stirng an array that should get enough room for one barcode line.
- WRITETEXT is used because in RTC i could not use WRITE and a lenth with a TEXT variable, maybe a bug, but with writetext it works.
- performance: with original code, report had 2.5 sec to execute in classic mode, after changes made it was around 0.2 sec.
- The performance should be definitly increased if you use a higher scale then 1
btw: very nice work! without that solution i wouldn’t be able to save a RDLC report as PDF (with SAVEASPDF) and have working barcode (SAVEASPDF mess things up when using barcode fonts)!
November 23rd, 2011 at 08:48
Hi,
great job about your source.
I’m trying to print a vertical barcode and it’s still too big. I had review code and minimum resolution is one.
How can I do barcode smaller?
it’s code128 with 12 digits and it prints 4.1 cm barcode. I will need 3.1 or less
Regards