TextExtractTest.vb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. Imports ComPDFKit.PDFDocument
  2. Imports System
  3. Imports System.IO
  4. Module TextExtractTest
  5. Private parentPath As String =
  6. Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())))
  7. Private outputPath As String = Path.Combine(parentPath, "Output", "VB")
  8. Sub Main(args As String())
  9. ' Preparation work
  10. Console.WriteLine("Running PDFPage test sample..." & vbCrLf)
  11. SDKLicenseHelper.LicenseVerify()
  12. Dim document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
  13. If Not Directory.Exists(outputPath) Then
  14. Directory.CreateDirectory(outputPath)
  15. End If
  16. If PDFToText(document) Then
  17. Console.WriteLine("PDF to text done.")
  18. Else
  19. Console.WriteLine("PDF to text failed.")
  20. End If
  21. Console.WriteLine("--------------------")
  22. Console.WriteLine("Done!")
  23. Console.WriteLine("--------------------")
  24. Console.ReadLine()
  25. End Sub
  26. ' Convert PDF to text
  27. Private Function PDFToText(document As CPDFDocument) As Boolean
  28. Dim filePath As String = Path.Combine(outputPath, "PDFToText.txt")
  29. If Not document.PdfToText("1-" & document.PageCount.ToString(), filePath) Then ' Page ranges are counted from 1
  30. Return False
  31. End If
  32. Console.WriteLine("Browse the generated file in " & filePath)
  33. Return True
  34. End Function
  35. End Module