コード例 #1
0
        public void InsertTextInField_InsertingTextTwice()
        {
            //Arrange
            byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);
            using (PdfUtility doc = new PdfUtility(file, null))
            {
                //Act

                //Inserting first time
                doc.InsertTextInField("Nome", "Pippo");
                //Inserting second time
                doc.InsertTextInField("Nome", "Pippo2");
            }
        }
コード例 #2
0
 public void InsertTextInField_FieldDoesntExist_FieldNotFoundException()
 {
     //Arrange
     byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);
     using (PdfUtility doc = new PdfUtility(file, null))
     {
         //Act
         doc.InsertTextInField("Nomi", "Pippo");
     }
 }
コード例 #3
0
 public void InsertTextInField_FieldExists()
 {
     //Arrange
     byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);
     using (PdfUtility doc = new PdfUtility(file, null))
     {
         //Act
         doc.InsertTextInField("Nome", "Pippo");
     }
 }
コード例 #4
0
 public void InsertTextInField_TextArgumentNull_ArgumentNullException()
 {
     //Arrange
     byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);
     using (PdfUtility doc = new PdfUtility(file, null))
     {
         //Act
         doc.InsertTextInField("Nome", null);
     }
 }
コード例 #5
0
 public void InsertTextInField_DocumentHasNoFields_DocumentHasNoFieldsException()
 {
     //Arrange
     byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS);
     using (PdfUtility doc = new PdfUtility(file, null))
     {
         //Act
         doc.InsertTextInField("Nome", "Pippo");
     }
 }
コード例 #6
0
        public void Save_DocumentTouched()
        {
            //Arrange
            byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);

            using (PdfUtility doc = new PdfUtility(file, null))
            {
                //Modifying file
                doc.FlagCheckbox("CheckBox1");
                doc.InsertTextInField("Nome", "Pippo");

                //Act
                var file_out = doc.Save();

                //checking if the given file isn't null
                Assert.IsTrue(file_out != null);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            int    option = 0;
            string name;
            string value;

            byte [] file = File.ReadAllBytes(FILENAME);

            using (PdfUtility p = new PdfUtility(file, PrintLog))
            {
                do
                {
                    Console.WriteLine("\nMENU\n\n1. Metodo: ricerca di un acrofield generico per name, l’oggetto ritornato deve indicare il tipo di acrofield(checkbox, textbox, signaturefield, radiobutton)\n2. Metodo: per flaggare un acrofield di tipo checkbox\n3. Metodo: per sostituire un acrofield di tipo signature con un acrofield di tipo checkbox\n4. Metodo: per selezionare un acrofield di tipo radiobutton\n5. Metodo: per inserire un testo in un acrofield di tipo testo\n6. Metodo: per ottenere il pdf elaborato\n7. Appiattisci pdf\n8. Esci\n\nInserisci la tua scelta:");
                    try
                    {
                        option = Int32.Parse(Console.ReadLine());
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("\nWrong command");
                    }

                    try
                    {
                        switch (option)
                        {
                        case 1:
                            Console.WriteLine("\nInsert field name: ");
                            name = Console.ReadLine();

                            int fieldType = p.GetAcrofieldType(name);
                            Console.WriteLine("Found type: " + fieldType + " (" + PdfUtility.GetFormType(fieldType) + ")");

                            break;

                        case 2:
                            Console.WriteLine("\nInsert checkbox name: ");
                            name = Console.ReadLine();

                            p.FlagCheckbox(name);
                            Console.WriteLine("Checked successfully!");
                            break;

                        case 3:
                            Console.WriteLine("\nInsert signaturefield name: ");
                            name = Console.ReadLine();

                            p.SubstituteSignature(name);
                            Console.WriteLine("Substituted successfully!");
                            break;

                        case 4:
                            Console.WriteLine("\nInsert radiobutton name: ");
                            name = Console.ReadLine();
                            Console.WriteLine("\nInsert value to select: ");
                            value = Console.ReadLine();

                            p.SelectRadiobutton(name, value);
                            Console.WriteLine("Renamed successfully!");
                            break;

                        case 5:
                            Console.WriteLine("\nInsert field name: ");
                            name = Console.ReadLine();
                            Console.WriteLine("\nInsert text: ");
                            value = Console.ReadLine();

                            p.InsertTextInField(name, value);
                            Console.WriteLine("Text inserted successfully!");
                            break;

                        case 6:
                            var data         = p.Save();
                            var filename_out = getModifiedFilename(FILENAME);
                            using (var fs = new FileStream(filename_out, FileMode.Create, FileAccess.Write))
                            {
                                fs.Write(data, 0, data.Length);
                            }

                            Console.WriteLine("File \"" + filename_out + "\" saved successfully!");
                            break;

                        case 7:
                            p.FlatteningDocument();
                            break;

                        case 8:
                            break;
                        }
                    }
                    catch (DocumentHasNoFieldsException)
                    {
                        Console.WriteLine("ERROR: Document has no fields");
                    }
                    catch (FieldNotFoundException)
                    {
                        Console.WriteLine("ERROR: Field not found");
                    }
                    catch (RadiobuttonValueNotFoundException)
                    {
                        Console.WriteLine("ERROR: The inserted value was not found in this radiobutton field");
                    }
                }while (option < 6 || option == 7 || option > 8);
            }
            CloseProgram();
        }