public void GetAcrofieldType_FieldDoesntExist_FieldNotFoundException()
 {
     //Arrange
     byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);
     using (PdfUtility doc = new PdfUtility(file, null))
     {
         //Act
         var type = doc.GetAcrofieldType("Nomi");
     }
 }
 public void GetAcrofieldType_ArgumentNull_ArgumentNullException()
 {
     //Arrange
     byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);
     using (PdfUtility doc = new PdfUtility(file, null))
     {
         //Act
         var type = doc.GetAcrofieldType(null);
     }
 }
 public void GetAcrofieldType_DocumentHasNoFields_DocumentHasNoFieldsException()
 {
     //Arrange
     byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS);
     using (PdfUtility doc = new PdfUtility(file, null))
     {
         //Act
         var type = doc.GetAcrofieldType("Nomi");
     }
 }
        public void GetAcrofieldType_FieldExists_ReturnsFieldType()
        {
            //Arrange
            byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX);
            using (PdfUtility doc = new PdfUtility(file, null))
            {
                //Act
                var type = doc.GetAcrofieldType("Nome");
                System.Diagnostics.Debug.WriteLine("Looking for acrofield named \"Nome\", type: " + type + " (" + PdfUtility.GetFormType(type) + ")");

                //Assert
                Assert.IsTrue(type > -1);
            }
        }
Exemple #5
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();
        }