DocumentInfoTest.vb 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Imports ComPDFKit.PDFDocument
  2. Imports System
  3. Imports System.IO
  4. Module DocumentInfoTest
  5. Sub Main(args As String())
  6. Console.WriteLine("Running DocumentInfo test sample..." & vbCrLf)
  7. SDKLicenseHelper.LicenseVerify()
  8. ' Sample 1: Print information
  9. Dim document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
  10. PrintDocumentInfo(document)
  11. Console.WriteLine("--------------------")
  12. Console.WriteLine("Done.")
  13. Console.WriteLine("--------------------")
  14. Console.ReadLine()
  15. End Sub
  16. Public Function GetFileSize(filePath As String) As String
  17. Dim fileInfo As FileInfo = Nothing
  18. Try
  19. fileInfo = New FileInfo(filePath)
  20. Catch
  21. Return "0B"
  22. End Try
  23. If fileInfo IsNot Nothing AndAlso fileInfo.Exists Then
  24. Dim fileSize As Double = fileInfo.Length
  25. If fileSize > 1024 Then
  26. fileSize = Math.Round(fileSize / 1024, 2)
  27. If fileSize > 1024 Then
  28. fileSize = Math.Round(fileSize / 1024, 2)
  29. If fileSize > 1024 Then
  30. fileSize = Math.Round(fileSize / 1024, 2)
  31. Return fileSize & " GB"
  32. Else
  33. Return fileSize & " MB"
  34. End If
  35. Else
  36. Return fileSize & " KB"
  37. End If
  38. Else
  39. Return fileSize & " B"
  40. End If
  41. End If
  42. Return "0B"
  43. End Function
  44. Private Sub PrintDocumentInfo(document As CPDFDocument)
  45. Console.WriteLine("File Name: {0}", document.FileName)
  46. Console.WriteLine("File Size: {0}", GetFileSize(document.FilePath))
  47. Console.WriteLine("Title: {0}", document.GetInfo().Title)
  48. Console.WriteLine("Author: {0}", document.GetInfo().Author)
  49. Console.WriteLine("Subject: {0}", document.GetInfo().Subject)
  50. Console.WriteLine("Keywords: {0}", document.GetInfo().Keywords)
  51. Console.WriteLine("Version: {0}", document.GetInfo().Version)
  52. Console.WriteLine("Page Count: {0}", document.PageCount)
  53. Console.WriteLine("Creator: {0}", document.GetInfo().Creator)
  54. Console.WriteLine("Creation Data: {0}", document.GetInfo().CreationDate)
  55. Console.WriteLine("Allows Printing: {0}", document.GetPermissionsInfo().AllowsPrinting)
  56. Console.WriteLine("Allows Copying: {0}", document.GetPermissionsInfo().AllowsCopying)
  57. Console.WriteLine("Allows Document Changes: {0}", document.GetPermissionsInfo().AllowsDocumentChanges)
  58. Console.WriteLine("Allows Document Assembly: {0}", document.GetPermissionsInfo().AllowsDocumentAssembly)
  59. Console.WriteLine("Allows Commenting: {0}", document.GetPermissionsInfo().AllowsCommenting)
  60. Console.WriteLine("Allows FormField Entry: {0}", document.GetPermissionsInfo().AllowsFormFieldEntry)
  61. End Sub
  62. End Module