Convert number to barcode Code 128

In the past I’ve created barcodes by using code number supplied and a font (free 3 of 9).

This time I need to create the barcodes in Code 128 symbology. As far as I can understand the text has to be converted using a calculation/formula.

I have the font Code 128 and have used an on-line generator to encode some sample text, eg. 95141111020209 which ends up: .++"")q

When I apply the font it doesn’t match the known working samples I have.

Any help of which way forward appreciated.

If plugins are an option, MBS has a barcode plugin.

Thanks Tim, the MBS plugin is probably not what I need. I think I did look at that and it creates a pdf of the barcode which is not really what I’m after.

This is a work related project and something that I don’t have the time to code in Xojo myself because the encoding of 128 is too complicated.

The barcodes will be used in an InDesign document. These are for vouchers which there are approx. 80,000 of them!!

Normally this type of thing isn’t that hard because we have other plugins that work with (free of 9) barcodes which are in a database that and are simply created by applying the correct font (similar to datamerge).

All I really need is to be able to convert the number, which then “encodes” to the correct format - then I believe I can apply the correct font.

There are commercial plugins but these are very expensive. There is an old excel macro, but I don’t trust it.

Perhaps someone has already a simple tool that can do the conversion.? We could come to some arrangement for payment. Like I said, I don’t really want to create my own software from scratch.

Actually, no, it creates a picture object with the graphics for the desired barcode.

Barcode generators tend to run it two main groups: those that generate graphics (such as MBS) and those that are designed for use with a specific barcode “font”. The thing about these fonts is they tend to require text conversion algorithms which are specific to the vendor/designer of the “font” and barcode type.

For the barcode “fonts” I have used in the past, the conversion algorithm had to be supplied by the font vendor because only they know which code points represent given bar patterns. And the conversion was different for different barcodes, because the bar patterns are different. (Say Code 3 of 9 vs Code 128) I’ve also used different font vendors for a given font and they needed different conversion algorithms.

You either need a font AND conversion formula from the same vendor, OR you need to use a graphics barcode like MBS instead of a font based barcode.

Thanks Douglas, I didn’t think it would be that simple.

The MBS plugin is for Xojo, ie. it works “within” Xojo, correct? Therefore I would still have to come up with a way to implement it.

I do have details for the conversion formula, and also have a font - not sure if they would match though and it would take me a lot of effort to do the programming. I could also create my own font.

Like is said, this is a lot of work. My day job is in prepress for a printing company not a software developer so even if I did come up with something in my “own” time, I would likely be making a rod for my own back.

Thanks for the help anyway.

Correct. If the other output is not created by Xojo, then using a font based barcode is likely the easier solution.

The conversion formula and font need to be from the same author. I also don’t think you should try to create your own font.

I’d suggest you find the vendor/author of the font you have and obtain their conversion formula. They may not have a Xojo example, but they are likely to have a VB sample that would not be hard to migrate.

Or else find another font with a conversion formula that goes with it. A quick web search includes this link to a free Code 128 font. The page also has a link to a page it says contains code samples in various programming languages. It also says that page is in French. I did not pursue it though.

Yeah, I’ve seen and read that link before. It may well be the source of the font I have.
I did muck around with an online encoder just to see if the font worked but there were some random erroneous spaces added.

The font is Code128.ttf and I believe it’s the only version one floating around on the web.

I may investigate a bit further before I completely can the whole idea. The reality is that even if I came up with a solution, I would get nothing for it, except for a bit of kudos maybe - baaahhh! kudos is overrated.

here is a link to a free barcode generator source code.
I downloaded an old 1.0b version that did only powerpc and updated it to v2 which works with current systems.
no warranty, use at your own risk…

they generate code128.
it’s an xcode project.

here is the compiled app :

I pulled this out of an old project. I think this is the code128 piece, but I don’t know the font used. Does it look remotely similar to the algorithm you have? It might help you find out where your code is failing.

dim bar as string    // the value to encode
dim barcod as string  // the result to apply the font to
dim n as integer

if bar.len mod 2<> 0 then bar= "0"+ bar
for i= 1 to bar.len step 2
   n= val(mid(bar, i, 2))
   if n<= 93 then
      n= n+ 33
      n= n+ 103
   barcod= barcod+ chr(n)
barcod= chr(203)+ barcod+ chr(204)

This code was “left over” as a commented out section after we switched to 3 of 9, so it may not even be code128, although my failing memory thinks it is.


BLEH, just noticed my code is for EAN 13 and you need Code 128 :frowning:


How does


look for



Thanks guys, your help is very much appreciated.

@ Jean-Yves: Thanks for your efforts. I’ll have to wait till I get back to my work on Monday to check it out as I only have a windows machine at home. If it creates a graphic object then I would prefer not to go down that path.

@ Tim: I’m not sure what that is. There are some similarities to 128.
I haven’t constructed the algorithm or any code yet. This is what I have looked at: which is a good explanation of the symbology.

Computing the “checksum” digit is probably the most complicated part. I know what modulo is but I’ve read it a few times and it still hasn’t sunk in yet.

Regardless, the font needs to suit also. There is no reason why the client could not just use 3 of 9 as it’s much simpler - but Code 128 has the advantage of higher density within a smaller space - although not critical in this instance because they have plenty of space on the artwork to insert it.

All I need is a simple 2 column table. Column 1 shows the “English Readable” code and column 2 show the gobblygook text that converts to the barcode when the font is applied. I explored a formula in excel that someone had created but it didn’t look right.

Come to think of it, I wonder if there is a difference in encoding of the characters, ie. mac vs windows and that’s the reason it didn’t work?. I’ve only tried this on a mac.

this is that in Xojo:

If you do not have a Windows Hardware handly, you can install VirtualBox from:

Thanks Emile.

Sorry, my wording wasn’t clear.

re. “I know what modulo is but I’ve read it a few times and it still hasn’t sunk in yet.”

I meant to say:

“I understand what modulo is, and I’ve read the explanation on Computing the “checksum” digit a few times, and it still hasn’t sunk in yet exactly how the checksum is calculated”.

At my work I have both Windows and MacOS, but at home only Windows.


Download VirtualBox and install macOS on your Windows Hardware :wink:
(I do not try that).

Oh! I didn’t know you could do that - thanks for the tip.

But, that’s not really going to help because I don’t have a Mac version of InDesign, or any other Mac software to test things. I’ve got an old version of InDesign on my home windows machine that I can test with.

Like I said, all I need is a 2 column table or csv file. It’s not about the machine but about how to encode the data correctly.

Please download MBS plugins, put the barcode and DynaPDF plugins in your plugins folder and play with examples.

Our plugin can do barcode 128 as picture and as vector graphic and both can go in a PDF.

I don’t know if you are familiar with Einhugur plugins.
Einhugur (Bjorn Eiriksson) also has a very nice BarcodePlugin

Thanks Christian & Paul, much appreciated but I have already mentioned that I don’t want to use graphic elements. The font itself will create the barcode from the encoded text.

I’ve had some success in this area. The reason why the encoded text wasn’t working in InDesign was because “use typographers quotes” was selected in the preferences. Therefore, when I pasted the encoded text, InDesign converted the standard straight quotes to “curly” quotes.

Now that this has been resolved, I can move forward :).

To test this, I used an online encoder :
This encoded the test number: 95141111020209 to: .++"")q

I then copied the text into InDesign and applied the Code 128 font:

For independent verification I used this online barcode generator: and using the original number, created and downloaded the barcode.

Finally, I compared the results:

The red barcode is the font version and the black one is from the online generator. As far as I’m concerned, within tolerances, this is an exact match :slight_smile:

So now for the hard part. ie. COMPUTING THE CHECKSUM from the explanation in this link:

What isn’t clear is it says: Take the value of the start character (103, 104, or 105) and make that the starting value of the running checksum. The example uses 103. I think Code 128 has 3 different flavours: A (auto) and B and C, so perhaps that’s what is referred to.

The “weighting” reminds me of MSB and LSB in binary. I have to set a few hours aside and carefully look at this and then start to construct some code to do the conversion. Bit difficult at the moment.

[EDIT] This might sound a bit rude, but if someone has another way of generating the sample barcode and checking it, that would be very helpful. I’d rather rely on this forum than unknowns on the web. Cheers.

Steve, give this a quick try:


.++"")q (corrected code, you posted a number ending in 7 for that url but your main test is ending in 9)


If that works for you there’s VB source that should be easy to convert to Xojo.