FlattenTest.vb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Imports ComPDFKit.PDFDocument
  2. Imports ComPDFKit.PDFPage
  3. Imports System
  4. Imports System.IO
  5. Module FlattenTest
  6. Private outputPath As String = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) & "\Output\VB"
  7. Sub Main(args As String())
  8. Console.WriteLine("Running Flatten test sample..." & vbCrLf)
  9. SDKLicenseHelper.LicenseVerify()
  10. If Not Directory.Exists(outputPath) Then
  11. Directory.CreateDirectory(outputPath)
  12. End If
  13. ' Flatten
  14. Dim document As CPDFDocument = CPDFDocument.InitWithFilePath("Annotations.pdf")
  15. If Flatten(document) Then
  16. Console.WriteLine("Flatten done.")
  17. Else
  18. Console.WriteLine("Flatten failed.")
  19. End If
  20. Console.WriteLine("--------------------")
  21. document.Release()
  22. Console.WriteLine("Done")
  23. Console.WriteLine("--------------------")
  24. Console.ReadLine()
  25. End Sub
  26. ' Flatten documentation with comments
  27. Private Function Flatten(document As CPDFDocument) As Boolean
  28. Dim annotationCount As Integer = 0
  29. For i As Integer = 0 To document.PageCount - 1
  30. Dim page As CPDFPage = document.PageAtIndex(i)
  31. annotationCount += page.GetAnnotCount()
  32. Next
  33. Console.Write("{0} annotations in the file. ", annotationCount)
  34. Dim flattenPath As String = outputPath & "\FlattenTest.pdf"
  35. If Not document.WriteFlattenToFilePath(flattenPath) Then
  36. Return False
  37. End If
  38. Console.WriteLine("Browse the changed file in " & flattenPath)
  39. ' Verify: Check if the number of comments in the new document is 0
  40. Dim flattenDocument As CPDFDocument = CPDFDocument.InitWithFilePath(flattenPath)
  41. Dim newCount As Integer = 0
  42. For i As Integer = 0 To flattenDocument.PageCount - 1
  43. Dim page As CPDFPage = flattenDocument.PageAtIndex(i)
  44. newCount += page.GetAnnotCount()
  45. Next
  46. Console.WriteLine("{0} annotations in the new file. ", newCount)
  47. If Not (newCount = 0) Then
  48. Return False
  49. End If
  50. Return True
  51. End Function
  52. End Module