我像这样在 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 有点......什么都没有。