1

iTextSharp(C#)でiText(Java) http://itextpdf.com/examples/iia.php?id=297の例を次のように書き直しました。

var document = new Document(PageSize.A4);
        var writer = PdfWriter.GetInstance(document,
                                                 new FileStream(Path, FileMode.Create, FileAccess.Write,
                                                                FileShare.None));
        document.Open();
        var cb = writer.DirectContent;
        document.Add(new Paragraph("Barcode EAN.UCC-13"));
        var codeEan = new BarcodeEAN {Code = "230482304"};
        document.Add(new Paragraph("default:"));
        document.Add(codeEan.CreateImageWithBarcode(cb, BaseColor.BLACK, BaseColor.WHITE));
        codeEan.GuardBars = false;
        document.Add(new Paragraph("without guard bars:"));
        Image i = codeEan.CreateImageWithBarcode(cb, null, null);
        document.Add(i);
        codeEan.Baseline = -1f;
        codeEan.GuardBars = true;
        document.Add(new Paragraph("text above:"));
        document.Add(codeEan.CreateImageWithBarcode(cb, null, null));
        codeEan.Baseline = codeEan.Size;
        document.Close();

しかし、次の例外を取得します

Index was outside the bounds of the array.

       at iTextSharp.text.pdf.BarcodeEAN.GetBarsEAN13(String _code)
   at iTextSharp.text.pdf.BarcodeEAN.PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
   at iTextSharp.text.pdf.Barcode.CreateTemplateWithBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
   at iTextSharp.text.pdf.Barcode.CreateImageWithBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)

私の間違いはどこにありますか?その1:1の例はそこにあります...私はC#用のものを見つけられませんでしたが、C#ポートとDokuがないのは少し...何もありません。

4

1 に答える 1

1

ここでの問題は、BarcodeEANCodeプロパティに無効なEANバーコード値を指定していることです。EANバーコード値は、最小文字要件を含み、最後の桁がチェックサムである特定の形式である必要があります。この形式の詳細については、こちらをご覧ください。

EANバーコード値を検証するために利用できるリソースはたくさんあります。codeproject.comには、EAN13バーコードを検証し、特定の12桁のEAN13バーコード値のチェックサム桁を計算するC#コードの記事があります。

于 2012-06-29T15:59:40.530 に答える