.NET条码的iText [英] iText for .NET barcode

查看:127
本文介绍了.NET条码的iText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用iTextSharp库创建带有 EAN13 条形码的PDF. 我尝试生成值为" 023942432852 "的条形码.

I try to create a PDF with a EAN13 Bar-code using the iTextSharp library. I try to generate a barcode with the value "023942432852".

iTextSharp.text.Image imageEAN = codeEan.CreateImageWithBarcode(cb, null, null);

抛出System.IndexOutOfRangeException.

有代码:

Document pdfdoc = new Document(pageSize, _margSx, _margDx, _margUp, _margBo);
            PdfWriter writer = PdfWriter.GetInstance(pdfdoc, new FileStream(_path + @"\Barcode.pdf", FileMode.Create));


            pdfdoc.Open();

            PdfContentByte cb = writer.DirectContent;

            pdfdoc.PageSize.BackgroundColor = BaseColor.GRAY;


            BarcodeEAN codeEan = new BarcodeEAN();
            if (CreaChecksum)
                codeEan.GenerateChecksum = true;
            codeEan.ChecksumText = true;
            codeEan.CodeType = Barcode.EAN13;
            codeEan.Code = barcode;

            iTextSharp.text.Image imageEAN = codeEan.CreateImageWithBarcode(cb, null, null);
            imageEAN.ScaleAbsolute(100, 40);
            imageEAN.SetAbsolutePosition(pdfdoc.PageSize.Right - 150f, pdfdoc.PageSize.Bottom + 30f);   
            pdfdoc.Add(imageEAN);

推荐答案

顾名思义,EAN13条形码需要13位数字,就像EAN8条形码需要8位数字一样.您正在尝试为此string创建条形码:

As the name indicates an EAN13 bar code requires 13 digits, just like an EAN8 bar code requires 8 digits. You are trying to create a bar code for this string:

"023942432852"

当我计算此string中的位数时,我只找到12.一位数字丢失.请完成string的长度,使其为13.

When I count the number of digits in this string, I only find 12. One digit is missing. Please complete the string so that its length is 13.

这篇关于.NET条码的iText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆