Exemplo n.º 1
0
        public static void Run()
        {
            // Define a field with the fixed position
            TemplateField field = new TemplateField(
                new TemplateFixedPosition(new Rectangle(new Point(35, 135), new Size(100, 10))),
                "FromCompany");

            // Create a template
            Template template = new Template(new TemplateItem[] { field });

            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.SampleInvoicePdf))
            {
                // Parse the document by the template
                DocumentData data = parser.ParseByTemplate(template);

                // Print all extracted data
                for (int i = 0; i < data.Count; i++)
                {
                    Console.Write(data[i].Name + ": ");
                    PageTextArea area = data[i].PageArea as PageTextArea;
                    Console.WriteLine(area == null ? "Not a template field" : area.Text);
                }
            }
        }
        public static void Run()
        {
            // Define a field with the regular expression
            TemplateField field = new TemplateField(
                new TemplateRegexPosition("Tax"),
                "Tax");

            TemplateField linkedField = new TemplateField(
                new TemplateLinkedPosition(
                    "Tax",
                    new Size(100, 20),
                    new TemplateLinkedPositionEdges(false, false, true, false)),
                "TaxValue");

            // Create a template
            Template template = new Template(new TemplateItem[] { field, linkedField });

            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.SampleInvoicePdf))
            {
                // Parse the document by the template
                DocumentData data = parser.ParseByTemplate(template);

                // Print all extracted data
                for (int i = 0; i < data.Count; i++)
                {
                    Console.Write(data[i].Name + ": ");
                    PageTextArea area = data[i].PageArea as PageTextArea;
                    Console.WriteLine(area == null ? "Not a template field" : area.Text);
                }
            }
        }
        public static void Run()
        {
            // Define a "price" field
            TemplateField priceField = new TemplateField(
                new TemplateRegexPosition("\\$\\d+(.\\d+)?"),
                "Price");

            // Define a "email" field
            TemplateField emailField = new TemplateField(
                new TemplateRegexPosition("[a-z]+\\@[a-z]+.[a-z]+"),
                "Email");

            // Create a template
            Template template = new Template(new TemplateItem[] { priceField, emailField });

            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.SampleInvoicePdf))
            {
                // Parse the document by the template
                DocumentData data = parser.ParseByTemplate(template);

                // Print all extracted data
                for (int i = 0; i < data.Count; i++)
                {
                    // Print field name
                    Console.Write(data[i].Name + ": ");

                    // As we have defined only text fields in the template,
                    // we cast PageArea property value to PageTextArea
                    PageTextArea area = data[i].PageArea as PageTextArea;
                    Console.WriteLine(area == null ? "Not a template field" : area.Text);
                }
            }
        }
        public static void Run()
        {
            // Create a table template with the parameters
            TemplateTable table = new TemplateTable(
                new TemplateTableParameters(new Rectangle(new Point(35, 320), new Size(530, 55)), null),
                "Details",
                null);

            // Create a template
            Template template = new Template(new TemplateItem[] { table });

            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.SampleInvoicePdf))
            {
                // Parse the document by the template
                DocumentData data = parser.ParseByTemplate(template);

                // Print all extracted data
                for (int i = 0; i < data.Count; i++)
                {
                    Console.Write(data[i].Name + ": ");
                    // Check if the field is a table
                    PageTableArea area = data[i].PageArea as PageTableArea;
                    if (area == null)
                    {
                        continue;
                    }

                    // Iterate via table rows
                    for (int row = 0; row < area.RowCount; row++)
                    {
                        // Iterate via table columns
                        for (int column = 0; column < area.ColumnCount; column++)
                        {
                            // Get the cell value
                            PageTextArea cellValue = area[row, column].PageArea as PageTextArea;

                            // Print the space between columns
                            if (column > 0)
                            {
                                Console.Write("\t");
                            }

                            // Print the cell value
                            Console.Write(cellValue == null ? "" : cellValue.Text);
                        }

                        // Print new line
                        Console.WriteLine();
                    }
                }
            }
        }
        public static void Run()
        {
            // Define a "price" field
            TemplateField priceField = new TemplateField(
                new TemplateRegexPosition("\\$\\d+(.\\d+)?"),
                "Price");

            // Define a "email" field
            TemplateField emailField = new TemplateField(
                new TemplateRegexPosition("[a-z]+\\@[a-z]+.[a-z]+"),
                "Email");

            // Create a template
            Template template = new Template(new TemplateItem[] { priceField, emailField });

            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.SampleInvoicePdf))
            {
                // Parse the document by the template
                DocumentData data = parser.ParseByTemplate(template);

                // Print prices
                Console.WriteLine("Prices:");
                foreach (FieldData field in data.GetFieldsByName("Price"))
                {
                    PageTextArea area = field.PageArea as PageTextArea;
                    Console.WriteLine(area == null ? "Not a template field" : area.Text);
                }

                // Print emails
                Console.WriteLine("Emails:");
                foreach (FieldData field in data.GetFieldsByName("Email"))
                {
                    // As we have defined only text fields in the template,
                    // we cast PageArea property value to PageTextArea
                    PageTextArea area = field.PageArea as PageTextArea;
                    Console.WriteLine(area == null ? "Not a template field" : area.Text);
                }
            }
        }
Exemplo n.º 6
0
 public static void Run()
 {
     // Create an instance of Parser class
     using (Parser parser = new Parser(Constants.SampleFormsPdf))
     {
         // Extract data from PDF document
         DocumentData data = parser.ParseForm();
         // Check if form extraction is supported
         if (data == null)
         {
             Console.WriteLine("Form extraction isn't supported.");
             return;
         }
         // Iterate over extracted data
         for (int i = 0; i < data.Count; i++)
         {
             Console.Write(data[i].Name + ": ");
             PageTextArea area = data[i].PageArea as PageTextArea;
             Console.WriteLine(area == null ? "Not a template field" : area.Text);
         }
     }
 }
        public static void Run()
        {
            // Create an instance of Parser class
            using (Parser parser = new Parser(Constants.SampleInvoicePdf))
            {
                // Parse the document by the template
                DocumentData data = parser.ParseByTemplate(GetTemplate());

                // Check if form extraction is supported
                if (data == null)
                {
                    Console.WriteLine("Parse Document by Template isn't supported.");
                    return;
                }

                // Print extracted fields
                for (int i = 0; i < data.Count; i++)
                {
                    Console.Write(data[i].Name + ": ");
                    PageTextArea area = data[i].PageArea as PageTextArea;
                    Console.WriteLine(area == null ? "Not a template field" : area.Text);
                }
            }
        }