Program.cs
上传用户:towway102
上传日期:2022-07-04
资源大小:4k
文件大小:1k
源码类别:

文件操作

开发平台:

Visual C++

  1. using System;
  2. using System.IO;
  3. using org.pdfbox.pdmodel;
  4. using org.pdfbox.util;
  5. namespace Pdf2Text
  6. {
  7. class Program
  8. {
  9. /// <summary>
  10. /// The main entry point for the application.
  11. /// </summary>
  12. [STAThread]
  13. static void Main(string[] args)
  14. {
  15. DateTime start = DateTime.Now;
  16. if (args.Length < 2)
  17. {
  18. Console.WriteLine("Usage: PDF2TEXT <input filename (PDF)> <output filename (text)>");
  19. return;
  20. }
  21. using (StreamWriter sw = new StreamWriter(args[1]))
  22. {
  23. sw.WriteLine(parseUsingPDFBox(args[0]));
  24. }
  25. Console.WriteLine("Done. Took " + (DateTime.Now - start));
  26. // Console.ReadLine();
  27. }
  28. private static string parseUsingPDFBox(string input)
  29. {
  30. PDDocument doc = PDDocument.load(input);
  31. PDFTextStripper stripper = new PDFTextStripper();
  32. return stripper.getText(doc);
  33. }
  34. }
  35. }