Exemplo n.º 1
0
        //private string ReadParagraph()
        //{
        //    PdfReader reader = new PdfReader(textBox1.Text);
        //    AcroFields form = reader.AcroFields;
        //    var fields = form.Fields;
        //    foreach (var x in fields)
        //    {
        //        richTextBox1.Text += x.Key + "  , " + x.Value;
        //    }
        //    return null;
        //}
        private string FindAdress(SinglePdfLine ad)
        {
            string    ResultAddress         = null;
            PdfReader reader                = new PdfReader(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), textBox1.Text));
            TextWithFontExtractionStategy S = new TextWithFontExtractionStategy();
            string XmlDocument              = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, Int32.Parse(numericUpDown1.Value.ToString()), S);

            return(ResultAddress);
        }
Exemplo n.º 2
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Tempadress != null && Tempadress.URX != 0f && Tempadress.URY != 0f && Tempadress.LLX != 0f && Tempadress.LLY != 0f)
            {
                listView1.Items[SelectedIndex].SubItems[6].Text = Tempadress.URX.ToString();
                listView1.Items[SelectedIndex].SubItems[7].Text = Tempadress.URY.ToString();
                listView1.Items[SelectedIndex].SubItems[8].Text = Tempadress.LLX.ToString();
                listView1.Items[SelectedIndex].SubItems[9].Text = Tempadress.LLY.ToString();
            }


            //Only one item is allowed to select so selected index is also one
            var selectedCollection = listView1.SelectedItems;

            foreach (ListViewItem i in selectedCollection)
            {
                SelectedIndex = i.Index;
            }

            panel3.Enabled = true;
            Tempadress     = new ItextSharp.SinglePdfLine();
            var x = listView1.SelectedItems;

            foreach (ListViewItem i in x)
            {
                Tempadress.Address    = i.SubItems[0].Text;
                Tempadress.FontSize   = float.Parse(i.SubItems[1].Text);
                Tempadress.FontFamily = i.SubItems[2].Text;
                Tempadress.Bold       = bool.Parse(i.SubItems[3].Text);
                Tempadress.Italic     = bool.Parse(i.SubItems[4].Text);
                Tempadress.Color      = i.SubItems[5].Text;

                try
                {
                    Tempadress.URX = float.Parse(i.SubItems[6].Text);
                }
                catch (ArgumentException)
                { }
                try
                {
                    Tempadress.URY = float.Parse(i.SubItems[7].Text);
                }
                catch (ArgumentException)
                { }
                try
                {
                    Tempadress.LLX = float.Parse(i.SubItems[8].Text);
                }
                catch (ArgumentException)
                { }
                try
                {
                    Tempadress.LLY = float.Parse(i.SubItems[9].Text);
                }
                catch (ArgumentException)
                { }
            }
            Tempadress.DocumentType = textBoxDocumentType.Text;

            Numeric_KeyPad_Lock  = true;
            numericUpDown2.Value = (int)Tempadress.URX;
            numericUpDown3.Value = (int)Tempadress.URY;
            numericUpDown4.Value = (int)Tempadress.LLX;
            numericUpDown5.Value = (int)Tempadress.LLY;
            Numeric_KeyPad_Lock  = false;
            listView1.Select();
            listView1.HideSelection = false;
        }
Exemplo n.º 3
0
        private void FindFont(string extractedText)
        {
            string[] ExtractedTexts = extractedText.Split('\n');

            Numeric_KeyPad_Lock = true;
            PdfReader reader = new PdfReader(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), textBox1.Text));
            TextWithFontExtractionStategy S = new TextWithFontExtractionStategy();
            string XmlDocument = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, Int32.Parse(numericUpDown1.Value.ToString()), S);

            foreach (var extractedtext in ExtractedTexts)
            {
                try
                {
                    string Regexe = "(?<data><span.*?" + extractedtext + ".*?span>)";
                    //        Regex RegexObj = new Regex("(?<data><span.*?"   +Regexe+ ".*?span>)");


                    MatchCollection collection = Regex.Matches(XmlDocument, "(?<data><span.*?" + extractedtext.Replace(" ", @"\s") + ".*?span>)");

                    foreach (Match x in collection)
                    {
                        SinglePdfLine adobj = new ItextSharp.SinglePdfLine();
                        string        data  = x.Groups["data"].Value;

                        if (data.Contains("NOTBOLD"))
                        {
                            adobj.Bold = false;
                            data       = data.Replace("NOTBOLD", "");
                        }
                        else
                        {
                            adobj.Bold = true;
                            data       = data.Replace("BOLD", "");
                        }
                        adobj.Color      = Regex.Match(data, "<span style=.*?color=(?<data>.*?);.*?>").Groups["data"].Value;
                        adobj.FontFamily = Regex.Match(data, "<span style=\"font-family:(?<data>.*?);.*?").Groups["data"].Value;
                        string FontSize    = Regex.Match(data, "<span style=.*?font-size:(?<data>.*?);.*?>").Groups["data"].Value;
                        string coordinates = Regex.Match(data, "<span style=.*?coordinates:(?<data>.*?);.*?>").Groups["data"].Value;

                        string[] splits = coordinates.Split(',');
                        adobj.URX = float.Parse(splits[0]);
                        adobj.URY = float.Parse(splits[1]);
                        adobj.LLX = float.Parse(splits[2]);
                        adobj.LLY = float.Parse(splits[3]);


                        adobj.FontSize = float.Parse(FontSize);
                        ListViewItem item = new ListViewItem();
                        item.SubItems.Add("Address");
                        item.SubItems.Add("Size");
                        item.SubItems.Add("Font");
                        item.SubItems.Add("Bold");
                        item.SubItems.Add("Italic");
                        item.SubItems.Add("Color");
                        item.SubItems.Add("URX");
                        item.SubItems.Add("URY");
                        item.SubItems.Add("LLX");
                        item.SubItems.Add("LLY");
                        item.SubItems[0].Text = extractedtext;
                        item.SubItems[2].Text = adobj.FontFamily;
                        item.SubItems[1].Text = adobj.FontSize.ToString();
                        item.SubItems[3].Text = adobj.Bold.ToString();
                        item.SubItems[4].Text = adobj.Italic.ToString();
                        item.SubItems[5].Text = adobj.Color.ToString();

                        Tempadress = new SinglePdfLine();
                        try
                        {
                            numericUpDown2.Value  = (int)adobj.URX;
                            item.SubItems[6].Text = adobj.URX.ToString();
                            Tempadress.URX        = adobj.URX;
                        }
                        catch (ArgumentException)
                        {
                            MessageBox.Show("Argument Exception while Getting numeric box ");
                        }
                        try
                        {
                            numericUpDown3.Value  = (int)adobj.URY;
                            Tempadress.URY        = adobj.URY;
                            item.SubItems[7].Text = adobj.URY.ToString();
                        }
                        catch (ArgumentException)
                        {
                            MessageBox.Show("Argument Exception while Getting numeric box ");
                        }
                        try
                        {
                            numericUpDown4.Value  = (int)adobj.LLX;
                            Tempadress.LLX        = adobj.LLX;
                            item.SubItems[8].Text = adobj.LLX.ToString();
                        }
                        catch (ArgumentException)
                        {
                            MessageBox.Show("Argument Exception while Getting numeric box ");
                        }
                        try
                        {
                            numericUpDown5.Value  = (int)adobj.LLY;
                            Tempadress.LLY        = adobj.LLY;
                            item.SubItems[9].Text = adobj.LLY.ToString();
                        }
                        catch (ArgumentException)
                        {
                            MessageBox.Show("Argument Exception while Getting numeric box ");
                        }

                        adobj.DocumentType = textBoxDocumentType.Text;
                        listView1.Items.Add(item);
                        listView1.Update();
                        Numeric_KeyPad_Lock  = false;
                        radioButton3.Checked = true;
                    }
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Input String contains invalid characters");
                }
            }
        }