TextExtractTest.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using ComPDFKit.PDFDocument;
  2. using System;
  3. using System.IO;
  4. namespace TextExtractTest
  5. {
  6. internal class TextExtractTest
  7. {
  8. static private string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + "\\Output\\TextExtract";
  9. static void Main(string[] args)
  10. {
  11. #region Perparation work
  12. Console.WriteLine("Running PDFPage test sample…\r\n");
  13. SDKLicenseHelper.LicenseVerify();
  14. CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
  15. if (!Directory.Exists(outputPath))
  16. {
  17. Directory.CreateDirectory(outputPath);
  18. }
  19. #endregion
  20. if (PDFToText(document))
  21. {
  22. Console.WriteLine("PDF to text done.");
  23. }
  24. else
  25. {
  26. Console.WriteLine("PDF to text failed.");
  27. }
  28. Console.WriteLine("--------------------");
  29. Console.WriteLine("Done!");
  30. Console.WriteLine("--------------------");
  31. Console.ReadLine();
  32. }
  33. //
  34. static private bool PDFToText(CPDFDocument document)
  35. {
  36. string path = outputPath + "//PDFToText.txt";
  37. if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
  38. {
  39. return false;
  40. }
  41. Console.WriteLine("Browse the generated file in " + path);
  42. return true;
  43. }
  44. }
  45. }