TextExtractTest.cs 1.6 KB

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