예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load a pdf document
            string      input = @"..\..\..\..\..\..\Data\FillFormField.pdf";
            PdfDocument doc   = new PdfDocument();

            doc.LoadFromFile(input);
            //Get pdf forms
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            //Fill pdf form fields
            for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
            {
                PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
                    switch (textBoxField.Name)
                    {
                    case "email":
                        textBoxField.Text = "*****@*****.**";
                        break;

                    case "username":
                        textBoxField.Text = "E-iceblue";
                        break;

                    case "password":
                        textBoxField.Password = true;
                        textBoxField.Text     = "e-iceblue";
                        break;

                    case "password2":
                        textBoxField.Password = true;
                        textBoxField.Text     = "e-iceblue";
                        break;

                    case "company_name ":
                        textBoxField.Text = "E-iceblue";
                        break;

                    case "first_name":
                        textBoxField.Text = "James";
                        break;

                    case "last_name":
                        textBoxField.Text = "Chen";
                        break;

                    case "middle_name":
                        textBoxField.Text = "J";
                        break;

                    case "address1":
                        textBoxField.Text = "Chengdu";
                        break;

                    case "address2":
                        textBoxField.Text = "Beijing";
                        break;

                    case "city":
                        textBoxField.Text = "Shanghai";
                        break;

                    case "postal_code":
                        textBoxField.Text = "11111";
                        break;

                    case "state":
                        textBoxField.Text = "Shanghai";
                        break;

                    case "phone":
                        textBoxField.Text = "1234567901";
                        break;

                    case "mobile_phone":
                        textBoxField.Text = "123456789";
                        break;

                    case "fax":
                        textBoxField.Text = "12121212";
                        break;
                    }
                }

                if (field is PdfListBoxWidgetFieldWidget)
                {
                    PdfListBoxWidgetFieldWidget listBoxField = field as PdfListBoxWidgetFieldWidget;
                    switch (listBoxField.Name)
                    {
                    case "email_format":
                        int[] index = { 1 };
                        listBoxField.SelectedIndex = index;
                        break;
                    }
                }

                if (field is PdfComboBoxWidgetFieldWidget)
                {
                    PdfComboBoxWidgetFieldWidget comBoxField = field as PdfComboBoxWidgetFieldWidget;
                    switch (comBoxField.Name)
                    {
                    case "title":
                        int[] items = { 0 };
                        comBoxField.SelectedIndex = items;
                        break;
                    }
                }

                if (field is PdfRadioButtonListFieldWidget)
                {
                    PdfRadioButtonListFieldWidget radioBtnField = field as PdfRadioButtonListFieldWidget;
                    switch (radioBtnField.Name)
                    {
                    case "country":
                        radioBtnField.SelectedIndex = 1;
                        break;
                    }
                }

                if (field is PdfCheckBoxWidgetFieldWidget)
                {
                    PdfCheckBoxWidgetFieldWidget checkBoxField = field as PdfCheckBoxWidgetFieldWidget;
                    switch (checkBoxField.Name)
                    {
                    case "agreement_of_terms":
                        checkBoxField.Checked = true;
                        break;
                    }
                }

                if (field is PdfButtonWidgetFieldWidget)
                {
                    PdfButtonWidgetFieldWidget btnField = field as PdfButtonWidgetFieldWidget;
                    switch (btnField.Name)
                    {
                    case "submit":
                        btnField.Text = "Submit";
                        break;
                    }
                }
            }

            string output = "FillFormField.pdf";

            //Save pdf document
            doc.SaveToFile(output);

            //Launch the file
            PDFDocumentViewer(output);
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            //Load a pdf document
            string      input = @"..\..\..\..\..\..\Data\AllFields.pdf";
            PdfDocument doc   = new PdfDocument();

            doc.LoadFromFile(input);

            //Get pdf forms
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            //Find pdf form fields
            for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
            {
                PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
                    //Get text of textbox
                    string text = textBoxField.Text;
                    sb.Append("The text in textbox is " + text + "\r\n");
                }

                if (field is PdfListBoxWidgetFieldWidget)
                {
                    PdfListBoxWidgetFieldWidget listBoxField = field as PdfListBoxWidgetFieldWidget;
                    sb.Append("Listbox items are \r\n");
                    //Get values of listbox
                    PdfListWidgetItemCollection items = listBoxField.Values;

                    foreach (PdfListWidgetItem item in items)
                    {
                        sb.Append(item.Value + "\r\n");
                    }
                    //Get selected value
                    string selectedValue = listBoxField.SelectedValue;
                    sb.Append("The selected value in the listbox is " + selectedValue + "\r\n");
                }

                if (field is PdfComboBoxWidgetFieldWidget)
                {
                    PdfComboBoxWidgetFieldWidget comBoxField = field as PdfComboBoxWidgetFieldWidget;
                    sb.Append("comBoxField items are \r\n");
                    //Get values of comboBox
                    PdfListWidgetItemCollection items = comBoxField.Values;

                    foreach (PdfListWidgetItem item in items)
                    {
                        sb.Append(item.Value + "\r\n");
                    }
                    //Get selected value
                    string selectedValue = comBoxField.SelectedValue;
                    sb.Append("The selected value in the comBoxField is " + selectedValue + "\r\n");
                }

                if (field is PdfRadioButtonListFieldWidget)
                {
                    PdfRadioButtonListFieldWidget radioBtnField = field as PdfRadioButtonListFieldWidget;
                    //Get value of radio button
                    string value = radioBtnField.Value;

                    sb.Append("The text in radioButtonField is " + value + "\r\n");
                }

                if (field is PdfCheckBoxWidgetFieldWidget)
                {
                    PdfCheckBoxWidgetFieldWidget checkBoxField = field as PdfCheckBoxWidgetFieldWidget;
                    //Get the checked state of the checkbox
                    bool state = checkBoxField.Checked;
                    sb.Append("If the checkBox is checked: " + state + "\r\n");
                }
            }
            string result = "GetAllValues.txt";

            File.WriteAllText(result, sb.ToString());

            //Launch file
            PDFDocumentViewer(result);
        }