PdfTextExtractor: New method HasText to determine if there is some text in the document.

This commit is contained in:
2016-06-27 12:20:24 +02:00
parent 7d9b7981a8
commit d46f8d2abe
6 changed files with 101 additions and 39 deletions

View File

@@ -17,6 +17,7 @@ namespace VAR.PdfTools.Workbench
txtPdfPath.Text = Properties.Settings.Default.LastPdfPath;
txtColumnName.Text = Properties.Settings.Default.LastColumnName;
txtFieldName.Text = Properties.Settings.Default.LastFieldName;
txtText.Text = Properties.Settings.Default.LastText;
}
private void FrmPdfInfo_FormClosing(object sender, FormClosingEventArgs e)
@@ -24,6 +25,7 @@ namespace VAR.PdfTools.Workbench
Properties.Settings.Default.LastPdfPath = txtPdfPath.Text;
Properties.Settings.Default.LastColumnName = txtColumnName.Text;
Properties.Settings.Default.LastFieldName = txtFieldName.Text;
Properties.Settings.Default.LastText = txtText.Text;
Properties.Settings.Default.Save();
}
@@ -132,5 +134,25 @@ namespace VAR.PdfTools.Workbench
}
txtOutput.Lines = fieldData.ToArray();
}
private void btnHasText_Click(object sender, EventArgs e)
{
if (System.IO.File.Exists(txtPdfPath.Text) == false)
{
MessageBox.Show("File does not exist");
return;
}
PdfDocument doc = PdfDocument.Load(txtPdfPath.Text);
List<string> lines = new List<string>();
int pageNum = 1;
foreach (PdfDocumentPage page in doc.Pages)
{
PdfTextExtractor extractor = new PdfTextExtractor(page);
lines.Add(string.Format("Page({0}) : {1}", pageNum, Convert.ToString(extractor.HasText(txtText.Text))));
}
txtOutput.Lines = lines.ToArray();
}
}
}