Exemplo n.º 1
0
        public string Extract(string filePath)
        {
            var extension = Path.GetExtension(filePath);

            if (extension == ".pdf")
            {
                var pdfParser = new PdfBoxParser();

                return pdfParser.ParseFile(filePath);
            }

            if (extension == ".txt")
            {
                using (TextReader reader = File.OpenText(filePath))
                {
                    return reader.ReadToEnd();
                }
            }

            throw new ArgumentException(string.Format("Extension '{0}' is not supported", extension));
        }
Exemplo n.º 2
0
        private static void TestPdfParser()
        {
            IPdfParser parser;
            try
            {
                parser = new PdfBoxParser();
            }
            catch (Exception e)
            {
                Console.WriteLine("1: {0}", e);
                return;
            }

            string result;
            try
            {
                result = parser.ParseFile("Tri_Dorogi.book.PDF");
                result = result.Replace("-" + Environment.NewLine, string.Empty);
            }
            catch (Exception e)
            {
                Console.WriteLine("2: {0}", e);
                return;
            }

            using (var writer = File.CreateText("output.txt"))
            {
                writer.Write(result);
            }
        }