Пример #1
0
        private void GenerateFieldRow(PDFTemplet fieldsInfo,KeyValuePair<string, string> de)
        {
            string fieldKey = de.Value.ToString();//value!!!
            //string fieldValue = pdfReader.AcroFields.GetField(fieldKey);

            bool editable = fieldsInfo.GetItem(fieldKey).Editable;//该字段是否可以被编辑
            if (!editable) return;

            string showtitle = fieldsInfo.GetItem(fieldKey).FieldTitle;
            string note = fieldsInfo.GetItem(fieldKey).Note;

            TableRow row = new TableRow();

            TableCell cell_1 = new TableCell();
            TableCell cell_2 = new TableCell();

            Literal lt = new Literal();
            TextBox tb = new TextBox();
            Literal ltnote = new Literal();
            if (showtitle.Equals("")) showtitle = fieldKey;

            lt.Text = "<span title='" + fieldKey + "'>" + showtitle + "&nbsp;</span>:";
            tb.Text = "";// fieldValue;
            tb.ID = "txt_" + fieldKey; //textbox的命名为txt_fieldkey
            ltnote.Text = note;

            //this.Controls.Add(tb);

            cell_1.Controls.Add(lt);
            cell_2.Controls.Add(tb);
            cell_2.Controls.Add(ltnote);

            row.Cells.Add(cell_1);
            row.Cells.Add(cell_2);

            FieldsHolderTable.Rows.Add(row);
        }
Пример #2
0
        //创建pdf中field对应的输入控件,依赖fieldsInfo中的字段属性
        private void CreateFieldControls(PDFTemplet fieldsInfo ,string templetefileserverpath)
        {
            this.FieldsHolderTable.Rows.Clear();

            PdfReader pdfReader = new PdfReader(templetefileserverpath);
            //将pdf中的字段,存在于fieldInfo中的,放入到sl中,其他放到dictionary中
            SortedList<string, string> sortedkeys = new SortedList<string, string>();
            Dictionary<string, string> unsortedkeys = new Dictionary<string, string>();
            foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
            {
                string fieldKey = de.Key.ToString();
                string ordervalue = fieldsInfo.GetItem(fieldKey).Order;
                if (ordervalue.Equals("-1")) { unsortedkeys.Add(fieldKey, fieldKey); }//key与value相同!!!
                else { sortedkeys.Add(ordervalue, fieldKey); }

            }
            //循环sorted list
            foreach (KeyValuePair<string, string> de in sortedkeys)
            {
                GenerateFieldRow(fieldsInfo, de);
            }
            //循环unsorted list
            foreach (KeyValuePair<string, string> de in unsortedkeys)
            {
                GenerateFieldRow(fieldsInfo, de);
            }
        }