测试例子(翻译自Chap13_form.java程序,已经成功转为Chap13_form.cs,iTextSharp中没有收录这个iText下的教程代码):
            String[,] colorvalues = {{"#FF0000", "Red"}, {"#00FF00", "Green"}, {"#0000FF", "Blue"}};

            acroForm.AddSelectList("list2", colorvalues, "#0000FF", helv, fontSize, 315, 550, 450, 600);
            acroForm.AddComboBox("combo2", colorvalues, "#0000FE", false, helv, fontSize, 315, 440, 450, 490);

出错:System.IndexOutOfRangeException

AddComboBox的bug比较隐蔽,除非你故意把defaultValue输为colorvalues 数组中不存在的值,否则不会导致错误抛出。

public PdfFormField AddComboBox(string name, string[,] options, string defaultValue, bool editable, BaseFont font, float fontSize, float llx, float lly, float urx, float ury) {
        PdfFormField choice = PdfFormField.CreateCombo(writer, editable, options, 0);
        SetChoiceParams(choice, name, defaultValue, llx, lly, urx, ury);
        string value = null;
        for (int i = 0; i < options.GetLength(0); i++) {//Steven Lee 20050819,原来为options.Length
            if (options[i, 0].Equals(defaultValue)) {
                value = options[i, 1];
                break;
            }
        }
        if (value == null) {
            value = options[0, 1];
        }
        DrawSingleLineOfText(choice, value, font, fontSize, llx, lly, urx, ury);
        AddFormField(choice);
        return choice;
    }

public PdfFormField AddSelectList(string name, string[,] options, string defaultValue, BaseFont font, float fontSize, float llx, float lly, float urx, float ury) {
        PdfFormField choice = PdfFormField.CreateList(writer, options, 0);
        SetChoiceParams(choice, name, defaultValue, llx, lly, urx, ury);
        StringBuilder text = new StringBuilder();
        for (int i = 0; i < options.GetLength(0); i++) {//Steven Lee 20050819,原来为options.Length
            text.Append(options[i, 1]).Append("\n");
        }
        DrawMultiLineOfText(choice, text.ToString(), font, fontSize, llx, lly, urx, ury);
        AddFormField(choice);
        return choice;
    }


1条评论

  1. LZ 或是各位

    有没有知道怎么使用ITexsharp 作贝斯曲线

    一直两个点的坐标,作出相应贝斯权限。

    望不吝赐教。

    谢谢!

发表评论

评论也有版权!