public static string GetInvoiceLineItemDataForRect(int invoiceNo, int X1, int Y1, int X2, int Y2) { if (invoiceNo >= invoiceDataList.Count) { return("Invoice No Error"); } List <OcrWord> ocrWordList = new List <OcrWord>(); int x = Math.Min(X1, X2); int y = Math.Min(Y1, Y2); int w = Math.Abs(X1 - X2); int h = Math.Abs(Y1 - Y2); string wordListInRect = ""; int wordCount = 0; try { StreamReader sr = new StreamReader(invoiceDataList[invoiceNo].textFilePath); while (true) { string line = sr.ReadLine(); OcrWord ocrWord = new OcrWord(); if (sr.EndOfStream || !ocrWord.readFromLine(line)) { break; } ocrWordList.Add(ocrWord); } bool ok = true; int lineSpace = 0; while (ok) { ok = false; for (int i = 0; i < ocrWordList.Count; i++) { if (ocrWordList[i].intersects(x, y, w, h + lineSpace)) { wordListInRect += ocrWordList[i].toString() + "\r\n"; wordCount++; ok = true; ocrWordList.RemoveAt(i); i--; } } y += h + lineSpace; lineSpace = h; } return(string.Format("Count = {0}\r\n{1}", wordCount, wordListInRect)); } catch { return("Text File Read Error"); } }
public static string GetInvoiceDataForRect(int invoiceNo, int X1, int Y1, int X2, int Y2) { if (invoiceNo >= invoiceDataList.Count) { return("Invoice No Error"); } int x = Math.Min(X1, X2); int y = Math.Min(Y1, Y2); int w = Math.Abs(X1 - X2); int h = Math.Abs(Y1 - Y2); string wordListInRect = ""; int wordCount = 0; try { StreamReader sr = new StreamReader(invoiceDataList[invoiceNo].textFilePath); while (true) { string line = sr.ReadLine(); OcrWord ocrWord = new OcrWord(); if (sr.EndOfStream || !ocrWord.readFromLine(line)) { break; } if (ocrWord.intersects(x, y, w, h)) { wordListInRect += ocrWord.toString() + "\r\n"; wordCount++; } } return(string.Format("Count = {0}\r\n{1}", wordCount, wordListInRect)); } catch { return("Text File Read Error"); } }