Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using iTextSharp.text.pdf;
- using iTextSharp.text.pdf.parser;
- using System.IO;
- using iTextSharp.text;
- using System.Globalization;
- using static System.Net.Mime.MediaTypeNames;
- namespace ConsoleApp5
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string PathKeyword = "C:/ftp/keyword.txt";
- string FilePath = @"C:/ftp/pdf/";
- string SaveFilePath = "C://ftp/AllCheck.txt";
- StringBuilder sb = new StringBuilder();
- List<StringBuilder> ListAllFiles = new List<StringBuilder>();
- List<string> ListForSave = new List<string>();
- string[] Keywords = File.ReadAllText(PathKeyword).Split(new string[] { "\r\n" }, StringSplitOptions.None);
- string[] DocPaths = System.IO.Directory.GetFiles(FilePath, "*.pdf");
- string text = string.Empty;
- //Создание списка всех PDF файлов
- foreach (string DocPath in DocPaths)
- {
- using (PdfReader reader = new PdfReader(DocPath))
- {
- for (int i = 1; i <= reader.NumberOfPages; i++)
- {
- text = string.Empty;
- ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
- text = PdfTextExtractor.GetTextFromPage(reader, i, strategy);
- text = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(text)));
- sb.Append(text);
- }
- }
- ListAllFiles.Add(sb);
- sb.Clear();
- }
- foreach (StringBuilder currentFile in ListAllFiles)
- {
- //ListForSave.Add(currentFile.ToString(20, 37));
- foreach (string keyword in Keywords)
- {
- if (currentFile.ToString().Contains(keyword))
- {
- int index = currentFile.ToString().IndexOf(keyword);
- string read = currentFile.ToString(index + keyword.Length + 1, 13);
- string[] words = read.Split('–');
- var number1 = Convert.ToDecimal(words[0], new CultureInfo("en-US"));
- var number2 = Convert.ToDecimal(words[1], new CultureInfo("en-US"));
- var median = (number1 + number2) / 2;
- Console.WriteLine($"Ключевое слово {keyword} его котировки равна от {number1} до {number2}. Медиана равна {median}");
- ListForSave.Add($"Ключевое слово {keyword} его котировки равна от {number1} до {number2}. Медиана равна {median}");
- }
- }
- }
- if (File.Exists(SaveFilePath))
- {
- File.Delete(SaveFilePath);
- }
- foreach (string list in ListForSave)
- {
- File.AppendAllText("C://ftp/AllCheck.txt", list + Environment.NewLine);
- }
- Console.WriteLine($"Файл с названием AllCheck.txt был создан в по пути C://ftp/AllCheck.txt");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement