Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //pdf file
            string input = "..\\..\\..\\..\\..\\..\\..\\Data\\FormField.pdf";

            //open pdf document
            PdfDocument doc = new PdfDocument(input);

            //get pdf form
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            //find the particular form field and delete it
            for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
            {
                PdfField field = formWidget.FieldsWidget.List[i] as PdfField;

                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;
                    if (textbox.Name == "password2")
                    {
                        formWidget.FieldsWidget.Remove(textbox);
                    }
                }
            }
            string output = "DeleteFormField.pdf";

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

            //Launching the Pdf file
            PDFDocumentViewer(output);
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Load from file
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\TextBoxSampleB.pdf");

            //Get form fields
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            //Get textbox
            PdfTextBoxFieldWidget textbox = formWidget.FieldsWidget["Text1"] as PdfTextBoxFieldWidget;

            //Set the font for textbox
            textbox.Font = new PdfTrueTypeFont(new Font("Tahoma", 12), true);

            //Set text
            textbox.Text = "Hello World";

            string result = "SetFontForFormField-result.pdf";

            //Save to file
            doc.SaveToFile(result);

            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load a pdf document
            string      input = @"..\..\..\..\..\..\Data\DeleteFormField.pdf";
            PdfDocument doc   = new PdfDocument();

            doc.LoadFromFile(input);

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

            //Find the particular form field and delete it
            for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
            {
                PdfField field = formWidget.FieldsWidget.List[i] as PdfField;

                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;
                    if (textbox.Name == "password2")
                    {
                        formWidget.FieldsWidget.Remove(textbox);
                    }
                }
            }
            string output = "DeleteFormField.pdf";

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

            //Launch the file
            PDFDocumentViewer(output);
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Pdf file path
            string input = @"..\..\..\..\..\..\Data\FormField.pdf";
            //Open pdf document
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(input);

            PdfFormWidget form = pdf.Form as PdfFormWidget;

            for (int i = 0; i < form.FieldsWidget.List.Count; i++)
            {
                PdfField field = form.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;

                    //Find the textbox named total
                    if (textbox.Name == "TextBox1")
                    {
                        textbox.Text = "New value";
                    }
                }
            }

            String result = "ModifyFormFieldValue_out.pdf";

            //Save the document
            pdf.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Load from file
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\TextBoxSampleB.pdf");

            //Get form fields
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            //Get textbox
            PdfTextBoxFieldWidget textbox = formWidget.FieldsWidget["Text1"] as PdfTextBoxFieldWidget;

            //Get the location of the textbox
            PointF location = textbox.Location;

            MessageBox.Show("The location of the field named " + textbox.Name + " is\n X:" + location.X + "  Y:" + location.Y);
        }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Load from file
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\TextBoxSampleB_1.pdf");

            //Get form fields
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            //Get textbox
            PdfTextBoxFieldWidget textbox = formWidget.FieldsWidget["Text1"] as PdfTextBoxFieldWidget;

            //Get the text of the textbox
            String text = textbox.Text;

            MessageBox.Show("The value of the field named " + textbox.Name + " is " + text);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument pdf = new PdfDocument();

            //Load a pdf document
            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\ExtractJavaScript.pdf");

            string js = null;

            PdfFormWidget form = pdf.Form as PdfFormWidget;

            for (int i = 0; i < form.FieldsWidget.List.Count; i++)
            {
                PdfField field = form.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;

                    //Find the textbox named total
                    if (textbox.Name == "total")
                    {
                        //Get the action
                        PdfJavaScriptAction jsa = textbox.Actions.Calculate;

                        if (jsa != null)
                        {
                            //Get JavaScript
                            js = jsa.Script;
                        }
                    }
                }
            }

            //Save and launch the result file
            File.WriteAllText("ExtractJavaScript.txt", js);
            System.Diagnostics.Process.Start("ExtractJavaScript.txt");
        }
Ejemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //pdf file
            string input = "..\\..\\..\\..\\..\\..\\..\\Data\\FormField.pdf";

            //open pdf document
            PdfDocument doc = new PdfDocument(input);

            //get pdf form
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            //find the particular form field and determine if it marks as required or not
            for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
            {
                PdfField field = formWidget.FieldsWidget.List[i] as PdfField;

                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;
                    if (textbox.Name == "username")
                    {
                        textbox.Required = true;
                    }
                    if (textbox.Name == "password2")
                    {
                        textbox.Required = false;
                    }
                }
            }
            string output = "result.pdf";

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

            //Launching the Pdf file
            PDFDocumentViewer(output);
        }
Ejemplo n.º 9
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);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (Profiles_ComboBox.Items.Count == 0)
            {
                _ = MessageBox.Show("Veuillez charger un fichier profiles.json avec des profiles remplis avant de générer une attestation.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                FileName = "attestation-deplacement-fr-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm") + ".pdf",
                Filter   = "Fichier PDF | *.pdf"
            };

            if (saveFileDialog.ShowDialog() ?? false)
            {
                try
                {
                    WebClient webClient = new WebClient();
                    webClient.DownloadFile("https://www.interieur.gouv.fr/attestation_de_deplacement_derogatoire", saveFileDialog.FileName);
                    PdfDocument doc = new PdfDocument();
                    doc.LoadFromFile(saveFileDialog.FileName);
                    PdfFormWidget formWidget = doc.Form as PdfFormWidget;
                    foreach (PdfField field in formWidget.FieldsWidget)// for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
                    {
                        if (field is PdfTextBoxFieldWidget)
                        {
                            PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
                            switch (textBoxField.Name)
                            {
                            case "Nom et prénom":
                                textBoxField.Text = Profiles_ComboBox.Text;
                                break;

                            case "Date de naissance":
                                textBoxField.Text = GetFromFullName(Profiles_ComboBox.Text).BirthDate;
                                break;

                            case "Lieu de naissance":
                                textBoxField.Text = GetFromFullName(Profiles_ComboBox.Text).BirthPlace;
                                break;

                            case "Adresse actuelle":
                                textBoxField.Text = GetFromFullName(Profiles_ComboBox.Text).Address;
                                break;

                            case "Ville":
                                textBoxField.Text = GetFromFullName(Profiles_ComboBox.Text).City;
                                break;

                            case "Date":
                                textBoxField.Text = DateTime.Now.ToString("dd/MM/yyyy");
                                break;

                            case "Heure":
                                textBoxField.Text = DateTime.Now.ToString("HH");
                                break;

                            case "Minute":
                                textBoxField.Text = DateTime.Now.ToString("mm");
                                break;

                            default:
                                break;
                            }
                        }
                        else if (field is PdfCheckBoxWidgetFieldWidget)
                        {
                            PdfCheckBoxWidgetFieldWidget checkBoxField = field as PdfCheckBoxWidgetFieldWidget;
                            if (checkBoxField.Name == Exit_Reasons_ComboBox.Text)
                            {
                                checkBoxField.Checked = true;
                            }
                        }
                    }
                    doc.SaveToFile(saveFileDialog.FileName);
                    _ = Process.Start("explorer.exe", saveFileDialog.FileName);
                }
                catch (Exception ex)
                {
                    _ = MessageBox.Show(ex.Message, "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Ejemplo n.º 11
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);
        }