DocumentCompareTest.vb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Imports ComPDFKit.Compare
  2. Imports ComPDFKit.PDFDocument
  3. Imports System
  4. Imports System.IO
  5. Module DocumentCompareTest
  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 PDFPage test sample..." & vbCrLf)
  9. SDKLicenseHelper.LicenseVerify()
  10. If Not Directory.Exists(outputPath) Then
  11. Directory.CreateDirectory(outputPath)
  12. End If
  13. Dim document1 As CPDFDocument = CPDFDocument.InitWithFilePath("ElectricalDiagram.pdf")
  14. Dim document2 As CPDFDocument = CPDFDocument.InitWithFilePath("ElectricalDiagram_New.pdf")
  15. If OverlayCompareDocument(document1, document2) Then
  16. Console.WriteLine("Compare document done.")
  17. Else
  18. Console.WriteLine("Compare document failed.")
  19. End If
  20. document1.Release()
  21. document2.Release()
  22. Console.WriteLine("--------------------")
  23. Dim document3 As CPDFDocument = CPDFDocument.InitWithFilePath("Text.pdf")
  24. Dim document4 As CPDFDocument = CPDFDocument.InitWithFilePath("TextChanged.pdf")
  25. If ContentCompareDocument(document3, document4) Then
  26. Console.WriteLine("Compare document done.")
  27. Else
  28. Console.WriteLine("Compare document failed.")
  29. End If
  30. document3.Release()
  31. document4.Release()
  32. Console.WriteLine("--------------------")
  33. Console.WriteLine("Done!")
  34. Console.WriteLine("--------------------")
  35. Console.ReadLine()
  36. End Sub
  37. Private Function OverlayCompareDocument(document1 As CPDFDocument, document2 As CPDFDocument) As Boolean
  38. Dim compareOverlay As New CPDFCompareOverlay(document1, "1-5", document2, "1-5")
  39. compareOverlay.Compare()
  40. Dim comparisonDocument As CPDFDocument = compareOverlay.ComparisonDocument()
  41. Dim path As String = outputPath & "\CompareDocumentTest.pdf"
  42. If Not comparisonDocument.WriteToFilePath(path) Then
  43. Return False
  44. End If
  45. Console.WriteLine("Browse the changed file in " & path)
  46. Return True
  47. End Function
  48. Private Function ContentCompareDocument(document As CPDFDocument, documentNew As CPDFDocument) As Boolean
  49. Dim compareContent As New CPDFCompareContent(document, documentNew)
  50. Dim pageCount As Integer = Math.Min(document.PageCount, documentNew.PageCount)
  51. For i As Integer = 0 To pageCount - 1
  52. Console.WriteLine("Page: {0}", i)
  53. Dim compareResults As CPDFCompareResults = compareContent.Compare(i, i, CPDFCompareType.CPDFCompareTypeAll, True)
  54. Console.WriteLine("Replace count: {0}", compareResults.ReplaceCount)
  55. Console.WriteLine("TextResults count: {0}", compareResults.TextResults.Count)
  56. Console.WriteLine("Delete count: {0}", compareResults.DeleteCount)
  57. Console.WriteLine("Insert count: {0}", compareResults.InsertCount)
  58. Next
  59. Return True
  60. End Function
  61. End Module