예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length < 1)
                {
                    DisplayUsage();
                    return;
                }
                LeadingCommas = False; LeadingJoins = True; RemoveComments = False
                                                                             string file = args[0];
                if (!File.Exists(file))
                {
                    file = Path.GetFullPath(file);
                    if (!File.Exists(file))
                    {
                        Console.WriteLine("Please give in the path to the PDF file.");
                    }
                }

                PDFParser pdfParser = new PDFParser();
                pdfParser.ExtractText(file, Path.GetFileNameWithoutExtension(file) + ".txt");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length < 1)
                {
                    DisplayUsage();
                    return;
                }

                //string file = args[0];

                var file = Environment.CurrentDirectory + "\\sample.pdf";  //it gets the pdf file from the debug folder

                if (!File.Exists(file))
                {
                    file = Path.GetFullPath(file);
                    if (!File.Exists(file))
                    {
                        Console.WriteLine("Please give in the path to the PDF file.");
                        Console.ReadLine();
                    }
                }

                PDFParser pdfParser = new PDFParser();
                pdfParser.ExtractText(file, Path.GetFileNameWithoutExtension(file) + ".txt"); //corresponding text file is saved at ~PDFToText_src\PdfToText\bin\Debug
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length < 1)
                {
                    DisplayUsage();
                    return;
                }

                string file = @"D:\Desktop\QlikBot User Access Guide.pdf";//args[0];
                if (!File.Exists(file))
                {
                    file = Path.GetFullPath(file);
                    if (!File.Exists(file))
                    {
                        Console.WriteLine("Please give in the path to the PDF file.");
                    }
                }

                PDFParser pdfParser = new PDFParser();
                pdfParser.ExtractText(file, Path.GetFileNameWithoutExtension(file) + ".txt");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length < 1)
                {
                    DisplayUsage();
                    return;
                }

                string file = args[0];
                if (!File.Exists(file))
                {
                    file = Path.GetFullPath(file);
                    if (!File.Exists(file))
                    {
                        Console.WriteLine("Please give in the path to the PDF file.");
                    }
                }

                PDFParser pdfParser = new PDFParser();
                pdfParser.ExtractText(file, Path.GetFileNameWithoutExtension(file)+".txt");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
예제 #5
0
파일: Form1.cs 프로젝트: vmouse/Minyust
        private void startParse()
        {
            if (pathCSV.Text.Length > 1 && pathPDF.Text.Length > 1 && files.Count > 0)
            {

                pb.Value = 0;
                pb.Maximum = files.Count;
                pb.Step = 1;
                ReportFile rf = null;
//                richTextBox1.Clear();

                //csv:  form; year; org; adres; inn; kpp; direktor + dolzh; buh; date; summ1; summ2;

                List<string> fcsv = new List<string>();
                if (listReports.Count < 0)
                {
                    fcsv.Add("Вид Отчета; Год отчета; Организация; Адрес; Moscow; ОГРН; Дата ЕГРЮЛ; ИНН; КПП; Сумма раздела 1; Сумма раздела 2; Директор; Дата отчета; Бухгалтер; Имя файла; Дата создания файла");
                }
                else
                {
                    fcsv.Add("Вид Отчета; Год отчета; Организация; Адрес; Moscow; ОГРН; Дата ЕГРЮЛ; ИНН; КПП; Сумма раздела 1; Сумма раздела 2; Директор; Дата отчета; Бухгалтер; Имя файла; Дата создания файла; НаименованиеНКО; Учетный номер; ОГРН; Форма; Вид отчета; Период;");
                }

                bool _add = false;

                PDFParser pf = new PDFParser();

                foreach (string filename in files)
                {
                    if (listReports.Count > 0)
                    {
                        rf = findInIndex(filename, listReports);
                    }

                    string csv_line = "";
                    _add = false;
                    pb.Value += 1;
                    try
                    {
                        int tot = 0;
                        string s = pf.ExtractText(filename, out tot);
                        

                        s = s.Replace('\n', '_');

                        Debug.WriteLine(">>>>>>>>>>>>" + tot);

                        int ifrm = s.IndexOf("Форма:)Tj") + 9;
                        int efrm = s.IndexOf("Q", ifrm);

                        string frm = s.Substring(ifrm, efrm - ifrm);
                        frm = GetWithIn(frm);

                        csv_line += FormatCSV(frm, 't');

//                        richTextBox1.AppendText("Форма документа: " + frm + '\n');

                        if (frm.Equals(viewReport.Text))
                        {
                            _add = true;
                            int za = s.IndexOf("за ");

                            string year = s.Substring(za + 3, 4);
//                            richTextBox1.AppendText("Год документа: " + year + '\n');

                            csv_line += FormatCSV(year, 'n');


                            int eid = s.IndexOf(@"(\(полное", za) - 9;

                            string naminc = s.Substring(za, eid - za);

//                            richTextBox1.AppendText("Организация: " + GetWithIn(naminc) + '\n');
                            csv_line += FormatCSV(GetWithIn(naminc),'t');

                            int adid = s.IndexOf(@"организации\))Tj", eid) + 16;
                            int eadid = s.IndexOf(@"(\(адрес", adid) - 8;

                            string addr = s.Substring(adid, eadid - adid);

//                            richTextBox1.AppendText("Адрес: " + GetWithIn(addr) + '\n');

                            addr = GetWithIn(addr);
                            csv_line += FormatCSV(addr, 't');

                            if (addr.IndexOf("осква") > 0)
                            {
                                csv_line += FormatCSV("1",'n');
                            }
                            else
                            {
                                csv_line += FormatCSV("0",'n');
                            }

                            int oid = s.IndexOf("(ОГРН:)Tj", eadid) + 8;
                            int eoid = s.IndexOf("F1 11 Tf", oid);

                            string textOgrn = s.Substring(oid, eoid - oid);

                            string ogr = GetWithIn(textOgrn);

                            csv_line += FormatCSV(ogr, 't');

//                            richTextBox1.AppendText("ОГРН: " + ogr + '\n');

                            int i_egrl = s.IndexOf("(ЕГРЮЛ)Tj", eoid) + 9;
                            int e_egrl = s.IndexOf("Q_q", i_egrl);

                            string s_d_egrul = s.Substring(i_egrl, e_egrl - i_egrl);

//                            richTextBox1.AppendText("ДАТА ЕГРЮЛ: " + GetWithIn(s_d_egrul) + '\n');

                            csv_line += FormatCSV(GetWithIn(s_d_egrul),'d');

                            int inn = s.IndexOf("(ИНН/КПП:)Tj", eoid) + 12;
                            int einn = s.IndexOf("F1 11 Tf", inn);

                            string sinn = s.Substring(inn, einn - inn);
//                            richTextBox1.AppendText("ИНН: " + GetWithIn(sinn) + '\n');

                            csv_line += FormatCSV(GetWithIn(sinn), 't');

                            int ekpp = s.IndexOf("F1 11 Tf", einn + 1);
                            string kpp = s.Substring(einn, ekpp - einn).Replace("/", "");

//                            richTextBox1.AppendText("КПП: " + GetWithIn(kpp) + '\n');

                            csv_line += FormatCSV(GetWithIn(kpp),'t');

                            double sumall = 0;

                            //1.1
                            int sone = s.IndexOf("(бюджета, бюджетов субъектов Российской Федерации, бюджетов)Tj");
                            int stwo = s.IndexOf("Q_q_2 J_0 G_Q_q_Q_q", sone);

                            string rt = s.Substring(sone, stwo - sone);
                            rt = clearRegX(rt);
//                            richTextBox1.AppendText("Сумма 1.1: " + getSumm(rt).ToString() + '\n');

                            sumall += getSumm(rt);

                            //1.2
                            stwo = s.IndexOf("расходования целевых денежных средств, полученных от российских)Tj", stwo);
                            int stri = s.IndexOf("Q_q_2 J_0 G_Q_q_Q_q", stwo);
                            string wt = s.Substring(stwo + 7, stri - stwo - 7);
                            wt = clearRegX(wt);
//                            richTextBox1.AppendText("Сумма 1.2: " + getSumm(wt).ToString() + '\n');

                            sumall += getSumm(wt);
                            //1.3
                            stri = s.IndexOf("(международных и иностранных организаций, иностранных граждан и лиц без)Tj", stri);
                            int otwo = s.IndexOf("Q_q_2 J_0 G_Q_q_Q_q", stri);
                            string tt = s.Substring(stri + 7, otwo - stri - 7);
                            tt = clearRegX(tt);
//                            richTextBox1.AppendText("Сумма 1.3: " + getSumm(tt).ToString() + '\n');

                            sumall += getSumm(tt);

//                            richTextBox1.AppendText("Общая сумма по разделу 1: " + sumall.ToString() + '\n');

                            csv_line += FormatCSV(sumall.ToString(), 'n');

                            //////////Раздел 2////////////

                            int i2s = s.IndexOf("(продажи товаров, выполнения работ, оказания услуг)Tj", otwo);
                            int ei2s = s.IndexOf("Q_q_2 J_0 G_Q_q_Q_q", i2s);
                            string s2s = s.Substring(i2s, ei2s - i2s);
                            s2s = clearRegX(s2s);

//                            richTextBox1.AppendText("Общая сумма по разделу 2: " + getSumm(s2s).ToString() + '\n');

                            sumall += getSumm(s2s);

                            int _min = int.Parse(minSumm.Text);
                            if (sumall < _min && _min > 0)
                            {
                                _add = false;
                            }

                            csv_line += FormatCSV(getSumm(s2s).ToString(), 'n');

                            //ФИО Руководителей

                            int ifio = s.IndexOf("(Лицо, имеющее право без доверенности действовать от имени некоммерческой организации:)Tj", ei2s) + 2;
                            int efio = s.IndexOf(@"(\(фамилия,", ifio);
                            string sfio = s.Substring(ifio, efio - ifio);

                            sfio = clearRegX(sfio);
                            sfio = GetWithIn(sfio);

//                            richTextBox1.AppendText(getDir(sfio) + " == " + getDolz(sfio) + '\n');

                            csv_line += FormatCSV(sfio, 't');

                            //дата отчета
                            int edat = s.IndexOf(@"(\(дата\", efio + 2) - 2;
                            string sdat = s.Substring(efio + 4, edat - efio);

                            sdat = GetWithIn(sdat);

//                            richTextBox1.AppendText(sdat + '\n');
                            csv_line += FormatCSV(sdat, 'd');

                            //Бухгалтер

                            int ibuh = s.IndexOf("(Лицо, ответственное за ведение бухгалтерского учета:)Tj", ifio) + 2;
                            int ebih = s.IndexOf(@"(\(фамилия", ibuh);

                            string sbuh = s.Substring(ibuh, ebih - ibuh);

                            sbuh = clearRegX(sbuh);
                            sbuh = GetWithIn(sbuh);

                            csv_line += FormatCSV(sbuh, 't');

//                            richTextBox1.AppendText(getDir(sbuh) + " == " + getDolz(sbuh));

                            csv_line += FormatCSV(filename, 't');

                            csv_line += FormatCSV(File.GetCreationTime(filename).ToString("dd.MM.yyyy"), 'd'); // filedate

                            if (rf != null)
                            {
                                csv_line += FormatCSV(rf.nameNKO, 't');
                                csv_line += FormatCSV(rf.indexFile, 't');
                                csv_line += FormatCSV(rf.ogrn, 't');
                                csv_line += FormatCSV(rf.formNKO, 't');
                                csv_line += FormatCSV(rf.vid, 't');
                                csv_line += FormatCSV(rf.period, 'n', true);
                            }
                        }
                        if (_add)
                        {
                            fcsv.Add(csv_line); 
                        }
                    }
                    catch { }

                }

                addToFile(fcsv);

            }
        }