示例#1
0
        private void AnalyzeAll(string path)
        {
            try
            {
                var directoryTop = Path.GetDirectoryName(path);
                var pdfs         = Directory.EnumerateFiles(directoryTop, "*.pdf");
                var count        = pdfs.Count();
                ShowMessage(string.Format("共找到 {0} 个pdf", count));
                int index = 0;
                int succ  = 0;
                foreach (var pdf in pdfs)
                {
                    index++;
                    ShowMessage(string.Format("\n{0} / {1} 正在解析 {2}", index, count, pdf));

                    try
                    {
                        var m         = CreditReportAnalyzer.Analyze(pdf);
                        var json      = SerializeToFormatJson(m);
                        var directory = Path.GetDirectoryName(pdf);
                        var fileName  = Path.GetFileNameWithoutExtension(pdf);
                        var pathThis  = Path.Combine(directory, fileName + ".json");
                        File.WriteAllText(pathThis, json, Encoding.UTF8);
                        succ++;
                        ShowMessage(string.Format("\n{0} / {1} 解析成功 {2}", index, count, pathThis));
                    }
                    catch (Exception e)
                    {
                        ShowMessage(string.Format("\n{0} / {1} 解析出错 {2}", index, count, e.Message));
                    }
                }
                ShowMessage(string.Format("\n解析完成,共 {0} 个,成功 {1} 个", count, succ));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#2
0
 private void Analyze()
 {
     try
     {
         if (string.IsNullOrWhiteSpace(txtPath.Text))
         {
             MessageBox.Show("需先选择征信报告pdf文件");
             return;
         }
         if (!File.Exists(txtPath.Text))
         {
             MessageBox.Show("征信报告pdf文件不存在");
             return;
         }
         txtContent.Text = "";
         var m = CreditReportAnalyzer.Analyze(txtPath.Text);
         txtContent.Text = SerializeToFormatJson(m);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }