/// <summary> /// This is the main method for extraction /// </summary> /// <param name="document"></param> /// <returns></returns> public TableResult GetTableContent(Document document) { TableResult result = new TableResult(this); // generate lines.. ArrayList lines = document.GenerateLines(DocumentArea); result.Init(lines); for (int i = 0; i < lines.Count; i++) { Line line = (Line)lines[i]; string s = line.Content; // iterate through all contained words and decide for each one, where it belongs to.. for (int j = 0; j < line.Words.Count; j++) { Word word = (Word)line.Words[j]; ColumnRequest column = GetContainingColumn(word.Bounds); if (column != null) { ColumnResult columnResult = result.GetColumnResult(line, column); if (columnResult != null) { // add word to the corresponding result element columnResult.Words.Add(word); } } } } return(result); }
public ColumnResult GetColumnResult(ColumnRequest column) { for (int i = 0; i < _ColumnResults.Count; i++) { ColumnResult result = (ColumnResult)_ColumnResults[i]; if (result.ColumnRequest == column) { return(result); } } return(null); }
public void Init(ArrayList lines) { for (int i = 0; i < lines.Count; i++) { Line line = (Line)lines[i] as Line; if (TableRequest.DocumentArea.Area.IntersectsWith(line.Bounds)) { LineResult newLine = new LineResult(); newLine.LineReference = line; for (int j = 0; j < TableRequest.ColumnRequests.Count; j++) { ColumnResult newColumn = new ColumnResult(); newColumn.ColumnRequest = TableRequest.ColumnRequests[j] as ColumnRequest; newLine.ColumnResults.Add(newColumn); } this.LineResults.Add(newLine); } } }
/// <summary> /// Fill content to listview. /// </summary> /// <param name="listview"></param> public void FillListViewItems(System.Windows.Forms.ListView listview) { listview.Items.Clear(); for (int i = 0; i < _lineResults.Count; i++) { LineResult lineResult = (LineResult)_lineResults[i]; ListViewItem newItem = new ListViewItem(); for (int j = 0; j < lineResult.ColumnResults.Count; j++) { ColumnResult colResult = (ColumnResult)lineResult.ColumnResults[j]; if (j == 0) { newItem.Text = colResult.GetContent(); } else { newItem.SubItems.Add(colResult.GetContent()); } } listview.Items.Add(newItem); } }
public void ExportToFile(string filename, string separator) { StreamWriter writer = File.CreateText(filename); for (int i = 0; i < _lineResults.Count; i++) { LineResult lineResult = (LineResult)_lineResults[i]; string lineContent = ""; for (int j = 0; j < lineResult.ColumnResults.Count; j++) { ColumnResult colResult = (ColumnResult)lineResult.ColumnResults[j]; string colContent = colResult.GetContent(); lineContent += colContent; if (j < lineResult.ColumnResults.Count - 1) { lineContent += separator; } } writer.WriteLine(lineContent); } writer.Close(); }