问题匹配使用iTextSharp与Barcode.4NET生成的Code128A条形码

时间:2022-09-06 22:18:11

First of all, I'm kinda new to the barcode formats and what I do know, I've learned from Wikipedia.

首先,我是条形码格式的新手和我所知道的,我从*学到的。

We have some barcodes generated by an existing app that uses the Barcode.4NET library. The barcode is in Code 128A format. The code to generate them is pretty simple, looking something like this:

我们有一些使用Barcode.4NET库的现有应用程序生成的条形码。条形码采用Code 128A格式。生成它们的代码非常简单,看起来像这样:

// Create the barcode
Code128ABarcode c128A = new Code128ABarcode("045746201627080857");

No other parameters are set for it - after setting the data, we just get a GIF version of the barcode back from the library.

没有为它设置其他参数 - 在设置数据后,我们只从库中获取条形码的GIF版本。

I'm working on a new app that is using iTextSharp for PDF generation and I figured that instead of using two libraries, I would use iTextSharp's barcode generation library since it supports Code128 barcodes. It has a few different variations of Code 128, but none of them are "Code 128A".

我正在开发一个使用iTextSharp进行PDF生成的新应用程序,我认为不使用两个库,我会使用iTextSharp的条形码生成库,因为它支持Code128条形码。它有一些Code 128的不同变体,但它们都不是“Code 128A”。

Here is what the code looks like for it:

以下是代码的样子:

Barcode128 code128 = new Barcode128();
code128.CodeType = Barcode.CODE128;
code128.ChecksumText = true;
code128.GenerateChecksum = true;
code128.StartStopText = true;
code128.Code = "045746201627080857";

The image below shows the best I've accomplished so far.

下图显示了迄今为止我所取得的最好成绩。

问题匹配使用iTextSharp与Barcode.4NET生成的Code128A条形码

The image on top is generated by iTextSharp and the one on the bottom is generated by Barcode4Net. Obviously, they aren't the same (and not just in the size and the font - the barcoded data is pretty different).

顶部的图像由iTextSharp生成,底部的图像由Barcode4Net生成。显然,它们不一样(并且不仅仅是尺寸和字体 - 条形码数据非常不同)。

Is anyone out there familiar enough with iTextSharp's (or iText itself) barcode components or with Code 128A barcodes to tell me how to make the iTextSharp one look exactly like the Barcode.4NET one?

有没有人熟悉iTextSharp(或iText本身)条形码组件或Code 128A条形码,告诉我如何使iTextSharp看起来像Barcode.4NET一样?

3 个解决方案

#1


3  

Is it really necessary for them to look exactly the same? The different versions of Code 128 are all capable of encoding numbers, even if the barcodes themselves look completely different; the reader should sort it all out in the end.

它们真的有必要看起来完全一样吗? Code 128的不同版本都能够编码数字,即使条形码本身看起来完全不同;读者最终应该全力以赴。

I prefer the B variant, because it has the lower case letters in addition to the upper case. You can see a table detailing the differences at http://www.barcodeisland.com/code128.phtml

我更喜欢B变体,因为它除了大写字母外还有小写字母。您可以在http://www.barcodeisland.com/code128.phtml上看到详细说明差异的表格

iTextSharp looks like it is generating variant C, which is the most compact if the text is only decimal digits. It encodes 2 digits in the same amount of space as a single character in the other encodings.

iTextSharp看起来像生成变量C,如果文本只是十进制数字,则它是最紧凑的。它在与其他编码中的单个字符相同的空间量中编码2个数字。

#2


3  

the number should be:

数字应该是:

*045746201627080857*

you need to add the asterisk to the start and the end so the Barcode can be readed, you need to check in the component documentation witch one needs this characters.

你需要在开头和结尾添加星号,以便可以重新编码条形码,你需要检查组件文档,这需要这个字符。

the scanner needs the leading and the trailing asterisk on this type of BC.

扫描仪需要此类BC上的前导和尾随星号。

for what I can see in your code, the line

我可以在你的代码中看到这一行

code128.StartStopText = true;

automatically adds it, try to set this property to false, you will end up with the same barcode. In the first code you should use

自动添加它,尝试将此属性设置为false,您将得到相同的条形码。在你应该使用的第一个代码中

Code128ABarcode c128A = new Code128ABarcode("*045746201627080857*");

try yourself :)

试试自己:)

Edited:

The correct barcode is:

正确的条形码是:

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

from the link below (using ID Automation free service):

从下面的链接(使用ID Automation免费服务):

http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

what you have is:

你拥有的是:

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

and this is Code128C instead of Code128A as you can check the link (I changed the barcode properties to Code128C)

这是Code128C而不是Code128A,因为你可以检查链接(我将条形码属性更改为Code128C)

http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

#3


1  

While I think balexandre has the generators mixed up, his advice is good.

虽然我认为balexandre混合了发电机,但他的建议很好。

Evidently Barcode.4NET is correctly generating the Code 128A barcode that I am trying to emulate.

显然Barcode.4NET正在生成我试图模拟的Code 128A条形码。

iTextSharp is generating a Code 128C barcode which, according to Mark Ransom, should be OK except for the users and customer will probably look at it and say "It's too short and should look like the other ones!"

根据Mark Ransom的说法,iTextSharp正在生成一个Code 128C条形码,除了用户和客户可能会看到它并说“它太短而且看起来应该像其他的一样!”之外应该没问题。

So, great advice, but I'm still back to "How do I generate a Code 128A barcode with iTextSharp?"

所以,很好的建议,但我仍然回到“如何使用iTextSharp生成Code 128A条码?”

#1


3  

Is it really necessary for them to look exactly the same? The different versions of Code 128 are all capable of encoding numbers, even if the barcodes themselves look completely different; the reader should sort it all out in the end.

它们真的有必要看起来完全一样吗? Code 128的不同版本都能够编码数字,即使条形码本身看起来完全不同;读者最终应该全力以赴。

I prefer the B variant, because it has the lower case letters in addition to the upper case. You can see a table detailing the differences at http://www.barcodeisland.com/code128.phtml

我更喜欢B变体,因为它除了大写字母外还有小写字母。您可以在http://www.barcodeisland.com/code128.phtml上看到详细说明差异的表格

iTextSharp looks like it is generating variant C, which is the most compact if the text is only decimal digits. It encodes 2 digits in the same amount of space as a single character in the other encodings.

iTextSharp看起来像生成变量C,如果文本只是十进制数字,则它是最紧凑的。它在与其他编码中的单个字符相同的空间量中编码2个数字。

#2


3  

the number should be:

数字应该是:

*045746201627080857*

you need to add the asterisk to the start and the end so the Barcode can be readed, you need to check in the component documentation witch one needs this characters.

你需要在开头和结尾添加星号,以便可以重新编码条形码,你需要检查组件文档,这需要这个字符。

the scanner needs the leading and the trailing asterisk on this type of BC.

扫描仪需要此类BC上的前导和尾随星号。

for what I can see in your code, the line

我可以在你的代码中看到这一行

code128.StartStopText = true;

automatically adds it, try to set this property to false, you will end up with the same barcode. In the first code you should use

自动添加它,尝试将此属性设置为false,您将得到相同的条形码。在你应该使用的第一个代码中

Code128ABarcode c128A = new Code128ABarcode("*045746201627080857*");

try yourself :)

试试自己:)

Edited:

The correct barcode is:

正确的条形码是:

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

from the link below (using ID Automation free service):

从下面的链接(使用ID Automation免费服务):

http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

what you have is:

你拥有的是:

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

and this is Code128C instead of Code128A as you can check the link (I changed the barcode properties to Code128C)

这是Code128C而不是Code128A,因为你可以检查链接(我将条形码属性更改为Code128C)

http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

#3


1  

While I think balexandre has the generators mixed up, his advice is good.

虽然我认为balexandre混合了发电机,但他的建议很好。

Evidently Barcode.4NET is correctly generating the Code 128A barcode that I am trying to emulate.

显然Barcode.4NET正在生成我试图模拟的Code 128A条形码。

iTextSharp is generating a Code 128C barcode which, according to Mark Ransom, should be OK except for the users and customer will probably look at it and say "It's too short and should look like the other ones!"

根据Mark Ransom的说法,iTextSharp正在生成一个Code 128C条形码,除了用户和客户可能会看到它并说“它太短而且看起来应该像其他的一样!”之外应该没问题。

So, great advice, but I'm still back to "How do I generate a Code 128A barcode with iTextSharp?"

所以,很好的建议,但我仍然回到“如何使用iTextSharp生成Code 128A条码?”