PDFATest.vb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Imports ComPDFKit.PDFDocument
  2. Imports System
  3. Imports System.IO
  4. Module PDFATest
  5. Private outputPath As String = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) & "\Output\VB"
  6. Sub Main()
  7. ' Perparation work
  8. Console.WriteLine("Running PDFA test sample…" & vbCrLf)
  9. SDKLicenseHelper.LicenseVerify()
  10. Dim document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
  11. If Not Directory.Exists(outputPath) Then
  12. Directory.CreateDirectory(outputPath)
  13. End If
  14. ' PDF/A-1a
  15. If CovertToPDFA1a(document) Then
  16. Console.WriteLine("Convert to PDF/A-1a done.")
  17. Else
  18. Console.WriteLine("Convert to PDF/A-1a failed.")
  19. End If
  20. document.Release()
  21. Console.WriteLine("--------------------")
  22. ' PDF/A-1b
  23. document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
  24. If CovertToPDFA1b(document) Then
  25. Console.WriteLine("Convert to PDF/A-1b done.")
  26. Else
  27. Console.WriteLine("Convert to PDF/A-1b failed.")
  28. End If
  29. document.Release()
  30. Console.WriteLine("--------------------")
  31. Console.WriteLine("Done!")
  32. Console.WriteLine("--------------------")
  33. Console.ReadLine()
  34. End Sub
  35. ' Save PDF as PDFA1a
  36. Public Function CovertToPDFA1a(document As CPDFDocument) As Boolean
  37. Dim convertToPDFA1aPath As String = outputPath & "\ConvertToPDFA1aTest.pdf"
  38. If Not document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath) Then
  39. Return False
  40. End If
  41. Console.WriteLine("Browse the changed file in " & convertToPDFA1aPath)
  42. Return True
  43. End Function
  44. ' Save PDF as PDFA1b
  45. Public Function CovertToPDFA1b(document As CPDFDocument) As Boolean
  46. Dim convertToPDFA1bPath As String = outputPath & "\ConvertToPDFA1bTest.pdf"
  47. If Not document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1b, convertToPDFA1bPath) Then
  48. Return False
  49. End If
  50. Console.WriteLine("Browse the changed file in " & convertToPDFA1bPath)
  51. Return True
  52. End Function
  53. End Module