Exemplo n.º 1
0
 protected override void Initialize()
 {
     config = Config as JPDataBackFillConfig;
     pa     = new PdfAnalyzer();
 }
        private string GetGear(string path, string ricCode)
        {
            string result = string.Empty;
            PDFDoc doc    = null;

            try
            {
                //PDFNet.Initialize();
                pdftron.PDFNet.Initialize("Reuters Technology China Ltd.(thomsonreuters.com):CPU:1::W:AMC(20121010):AD5EE33F2505D1CAF1B425461F9C92BAA89204FA0AD8AAA17E07887EF0FA");
                doc = new PDFDoc(path);
                doc.InitSecurityHandler();

                if (doc == null)
                {
                    string msg = string.Format("can't load pdf to doc = new PDFDoc({0}); ", path);
                    Logger.Log(msg, Logger.LogType.Error);
                    return(result);
                }

                int              x1         = 0;
                int              y1         = 0;
                int              xx1        = 0;
                PdfAnalyzer      pa         = new PdfAnalyzer();
                List <PdfString> listX1     = pa.RegexSearchAllPages(doc, ricCode);
                List <PdfString> listY1     = pa.RegexSearchAllPages(doc, @"[G|g]earing");
                List <PdfString> listXX1    = pa.RegexSearchAllPages(doc, @"[S|s]tock [C|c]ode");
                List <PdfString> listResult = pa.RegexSearchAllPages(doc, @"(?<Result>\d+\.\d+x)");

                if (listX1.Count == 0 || listY1.Count == 0 || listXX1.Count == 0 || listResult.Count == 0)
                {
                    string msg = string.Format("({0}),([G|g]earing),([S|s]tock [C|c]ode) exist missing value ,so Gearing is empty value.", ricCode);
                    Logger.Log(msg, Logger.LogType.Warning);
                    return(result);
                }

                x1  = System.Convert.ToInt32(listX1[0].Position.x1);
                xx1 = System.Convert.ToInt32(listXX1[0].Position.x1);
                int pdfX1 = 0;
                int sub   = 0;
                //get Gearing position (x1,y1)
                foreach (var item in listY1)
                {
                    pdfX1 = System.Convert.ToInt32(item.Position.x1);
                    sub   = pdfX1 - xx1;
                    if (sub < 0)
                    {
                        sub = 0 - sub;
                    }

                    if (sub <= 10)
                    {
                        y1 = System.Convert.ToInt32(item.Position.y1);
                        break;
                    }
                }

                int subX1 = 0;
                int subY1 = 0;
                //use Gearing position (x1,y1) to get the right result value
                foreach (var item in listResult)
                {
                    subX1 = x1 - System.Convert.ToInt32(item.Position.x1);
                    if (subX1 < 0)
                    {
                        subX1 = 0 - subX1;
                    }
                    subY1 = y1 - System.Convert.ToInt32(item.Position.y1);
                    if (subY1 < 0)
                    {
                        subY1 = 0 - subY1;
                    }

                    if (subX1 <= 10 && subY1 <= 10)
                    {
                        result = item.ToString().Replace("x", "");
                        return(result);
                    }
                }

                Logger.Log(string.Format("stock code:{0},extract gear failed .", ricCode), Logger.LogType.Error);
                return(result);
            }
            catch (Exception ex)
            {
                string msg = string.Format("PDF analysis failed for " + ricCode + "! Action: Need manually input gearing and premium \r\n error msg:{0}", ex.Message);
                Logger.Log(msg, Logger.LogType.Warning);
                return(result);
            }
        }