So an update, I've gotten my code to be able to read a single pdf file and parse the information into a text file. Great. Now I want to figure out how to do the following two things.
Get the program to be able to read more than 1 pdf file. If I could get it to read an entire file folder, that would be best. I'm not sure how to change the code to do that, but I know it can't be that different.
Change the activation method. If I could get it so that the code ran whenever a new file was dropped into a folder, that would be absolutely amazing. That has to be possible, to somehow have an event listener that activates whenever a file is dropped into a folder and parses the information.
public static string ExtractTextFromPdf(string path)
{
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
using (PdfReader reader = new PdfReader(path))
{
StringBuilder text = new StringBuilder();
for (int page = 1; page <= reader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(reader, page, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\kttricic\OneDrive - Burns & McDonnell\Desktop\test file\POs\test");
file.WriteLine(text);
file.Close();
return text.ToString();
}
}
static void Main(string[] args)
{
Console.WriteLine(ExtractTextFromPdf(@"C:\Users\kttricic\OneDrive - Burns & McDonnell\Desktop\test file\POs\PO 4505234816 Siemens Industry, Inc. 6.15.21.pdf"));
}