Problem creating these barcodes

I am trying to create barcode using the BarCodeGenerator class
setting barcode text property to the following string value “777777777+D0281726+1+10+0”;

For the encodetypes

GS1Code128 and GS1DataMatrix, I am getting the following exception

Wrong format of GS1 Code128 input string
Wrong format of GS1 DataMatrix input string

For encodeType PatchCode I am getting exception
Patch code format exception.
Try use Patch I, II, II, III, IV, T, VI in the inputed code text.

For encode type DataBarLimited I am getting exception
GTIN must start with 0 or 1 in DatabarLimited. For example (01)08888888888888 or (01)17777777777779.

I am not sure what I am doing wrong.
Is the barcode text value set up incorrectly ? Has to be prefixed with certain characters ?

Please elaborate or point me to the documentation on how to produce these bar codes

Thank you.

@nick1234,

Could you please share the code snippet and the files for our testing. We will reproduce the problem and provide our feedback after analysis.

using Aspose.BarCode;
using Aspose.BarCode.Generation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsposeBarCodeGenerator
{
class Program
{
public enum BarcodeFontTypes
{
None = 0,
Datamatrix = 1,
Pdf417 = 2,
MacroPdf417 = 3,
GS1DataMatrix = 4,
MicroPdf417 = 5,
GS1QR = 6,
MaxiCode = 7,
DotCode = 8,
AustraliaPost = 9,
Postnet = 10,
Planet = 11,
OneCode = 12,
RM4SCC = 13,
DatabarOmniDirectional = 14,
DatabarTruncated = 15,
Aztec = 16,
DatabarLimited = 17,
DatabarExpandedStacked = 18,
DatabarStacked = 19,
DatabarStackedOmniDirectional = 20,
SingaporePost = 21,
AustralianPosteParcel = 22,
SwissPostParcel = 23,
PatchCode = 24,
Code32 = 25,
DataLogic2of5 = 26,
DutchKIX = 27,
UpcaGs1Code128Coupon = 28,
UpcaGs1DatabarCoupon = 29,
CodablockF = 30,
GS1CodablockF = 31,
DatabarExpanded = 32,
QR = 33,
Code16K = 34,
UPCA = 35,
SSCC18 = 36,
SCC14 = 37,
EAN14 = 38,
EAN13 = 39,
EAN8 = 40,
Pharmacode = 41,
GS1Code128 = 42,
Code39Standard = 43,
Code39Extended = 44,
Code93Standard = 45,
Code93Extended = 46,
CodeBlockF = 47,
Code11 = 48,
Codabar = 49,
Code128 = 50,
ISBN = 51,
UPCE = 52,
ISMN = 53,
PZN = 54,
OPC = 55,
DeutschePostLeitcode = 56,
DeutschePostIdentcode = 57,
ISSN = 58,
MSI = 59,
VIN = 60,
Matrix2of5 = 61,
ITF14 = 62,
IATA2of5 = 63,
ItalianPost25 = 64,
Interleaved2of5 = 65,
Standard2of5 = 66,
ITF6 = 67
}
static void Main(string[] args)
{
LoadAsposeLicense();

		BuildBarCodeImage(EncodeTypes.GS1Code128);
		BuildBarCodeImage(EncodeTypes.GS1DataMatrix);
		BuildBarCodeImage(EncodeTypes.PatchCode);
		BuildBarCodeImage(EncodeTypes.DatabarExpandedStacked);
		BuildBarCodeImage(EncodeTypes.DatabarLimited);


	}

	private static void SetBarCodeGenerator(BarCodeGenerator barCodeGenerator, float width, float height, float left, float right, bool setWidth)
	{
		barCodeGenerator.AutoSizeMode = AutoSizeMode.Interpolation;
		barCodeGenerator.BarCodeHeight.Inches = height;
		barCodeGenerator.Margins.Left.Pixels = left;
		barCodeGenerator.Margins.Right.Pixels = right;

		if (setWidth)
			barCodeGenerator.BarCodeWidth.Inches = width;
	}

	private static void LoadAsposeLicense()
	{
		Aspose.BarCode.License bclicense = new Aspose.BarCode.License();

		var licenseFile = "Aspose.Total.lic"; 

		try
		{
			bclicense.SetLicense(licenseFile);
			Console.WriteLine("License set successfully.");
		}
		catch (Exception e)
		{

			Console.WriteLine("\nThere was an error setting the license: " + e.Message);
		}
	}

	public static void BuildBarCodeImage(SymbologyEncodeType encodeType)
	{
		BarCodeGenerator barCodeGenerator = new BarCodeGenerator(encodeType);

		string fileFolder = "c:\\temp\\asposefonts\\2\\";
		string filename = encodeType.TypeName + ".png";

		SetBarCodeGenerator(barCodeGenerator, 0, 1f, 0f, 0f, false);


		barCodeGenerator.CodeTextStyle.Location = CodeLocation.None;
		barCodeGenerator.CodeText = "777777777+D0281726+1+10+0";

		try
		{
			barCodeGenerator.Save(Path.Combine(fileFolder, filename), BarCodeImageFormat.Png);
		}
		catch (Exception ex)
		{

		}
	}

	public static void BuildSquareBarCodeImage(SymbologyEncodeType encodeType)
	{
		BarCodeGenerator barGen = new BarCodeGenerator(encodeType);

		string fileFolder = "c:\\temp\\asposefonts\\2\\";
		string filename = encodeType.TypeName + ".png";

		SetBarCodeGenerator(barGen, 1f, 1f, 0f, 0f, true);

		barGen.CodeTextStyle.Location = CodeLocation.None;
		barGen.CodeText = "777777777+D0281726+1+10+0";

		try
		{
			barGen.Save(Path.Combine(fileFolder, filename), BarCodeImageFormat.Png);
		}
		catch (Exception ex)
		{

		}
	}

}

}

@nick1234,

Each barcode type has a well-defined set of rules for the text which is used for generating these barcodes. You may please consider the following sample strings for testing along with the reference documents which are just googled. Please give them a try and share the feedback.

GS1Code128
https://www.barcodefaq.com/1d/gs1-128/
// barCodeGenerator.CodeText = “(01)30012345678906”

GS1DataMatrix
https://www.activebarcode.com/codes/gs1-datamatrix.html
// barCodeGenerator.CodeText = “(01)01234567890128(15)051231”

EncodeTypes.PatchCode
https://patchcode.kodakalaris.com/en/index.html
// barCodeGenerator.CodeText = “Patch I”
// barCodeGenerator.CodeText = “Patch II”
// barCodeGenerator.CodeText = “Patch III”
// barCodeGenerator.CodeText = “Patch IV”
// barCodeGenerator.CodeText = “Patch T”
// barCodeGenerator.CodeText = “Patch VI”

DatabarExpandedStacked
https://www.barcodefaq.com/1d/gs1-databar/
// barCodeGenerator.CodeText = “(01)00123456789012(15)991231”

DatabarLimited
https://cmbdn.cognex.com/gs1-databar?gclid=CjwKCAjw7_rlBRBaEiwAc23rhkR2hM_qzHwpXTEh5auvuJp-
YxueT3tN_XsilhGO1Fg0bbySUckLnBoCCgsQAvD_BwE
// barCodeGenerator.CodeText = “(01)01234567890128”

These links explains what the barcode types are… but do you have code snipplets of how to build them using your product ? Still not clear. Thanks

As you can see from my code.
I want to be able to scan it to the following text … “777777777+D0281726+1+10+0”

Are you saying that for some of these, I have to prefix with certain string ?
Then it won’t scan to what I want … right ?

Can you provide snipplet on how to do one of these

One more… GTIN as I understand it is a number associated with GS1 product (proprietary ? )
To get a GTIN number you need to have a company prefix assigned, is that right ?

@nick1234,

In the above post, if we consider the first type GS1Code128, it shows that if you want to generate barcode of this type then you should replace the string “777777777+D0281726+1+10+0” in your function BuildBarCodeImage(SymbologyEncodeType encodeType) with “(01)30012345678906”. In this case, your code will look like this:

public static void BuildBarCodeImage(SymbologyEncodeType encodeType)
	{
		BarCodeGenerator barCodeGenerator = new BarCodeGenerator(encodeType);

		string fileFolder = "c:\\temp\\asposefonts\\2\\";
		string filename = encodeType.TypeName + ".png";

		SetBarCodeGenerator(barCodeGenerator, 0, 1f, 0f, 0f, false);


		barCodeGenerator.CodeTextStyle.Location = CodeLocation.None;
		// barCodeGenerator.CodeText = "777777777+D0281726+1+10+0";
          barCodeGenerator.CodeText  = “(01)30012345678906”;

		try
		{
			barCodeGenerator.Save(Path.Combine(fileFolder, filename), BarCodeImageFormat.Png);
		}
		catch (Exception ex)
		{

		}
	}

For you reference your complete code is modified to create barcode image for say GS1Code128. In a similar manner, you should use the respective string in the above post to generate the required barcode.

SampleCode.zip (979 Bytes)

Please note that for EncodeTypes.PatchCode, you should use one string at a time like
// barCodeGenerator.CodeText = “Patch I”
OR
// barCodeGenerator.CodeText = “Patch II” and so on.

Yes, you are right that you need to buy a code for your company as mentioned in the following link:
https://www.cpcstrategy.com/blog/2018/08/upc-codes-amazon/

OK I was able to produce it for DataBar and GS128

But for Patch code if I set the barCodeGenerator.CodeText = “Patch II”
How is it going to scan to the data I want ? … wouldn’t it scan to the string “Patch I” ?
Where do I set my information ? ie … “777777777+D0281726+1+10+0” ?

@nick1234,

We have checked the documentation but could not find any option to set the optional Bar Code value. We have logged the issue in our database for investigation and for a fix (if applicable). Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

BARCODENET-37197 - Option to set Bar Code value while creating barcode of type PatchCode

Do we need to add Patch 10-15 support, because Patch1-6 + Patch T are officially standardized by Kodak, but Patch 10-15 are internal Kodak standards currently?

The issues you have found earlier (filed as BARCODENET-37197) have been fixed in Aspose.BarCode for .NET v20.4. This message was posted using Bugs notification tool by ahsaniqbalsidiqui