|
1 | 1 | package com.groupdocs.comparison.examples; |
2 | 2 | import java.awt.Color; |
| 3 | +import java.awt.Graphics; |
| 4 | +import java.awt.image.BufferedImage; |
| 5 | +import java.io.File; |
3 | 6 | import java.io.FileInputStream; |
4 | 7 | import java.io.InputStream; |
5 | 8 | import java.util.Arrays; |
6 | 9 | import java.util.List; |
7 | 10 |
|
| 11 | +import javax.imageio.ImageIO; |
| 12 | + |
8 | 13 | import com.groupdocs.comparison.Comparer; |
9 | 14 | import com.groupdocs.comparison.MultiComparer; |
10 | | -import com.groupdocs.comparison.common.changes.ChangeInfo; |
11 | | -import com.groupdocs.comparison.common.changes.ComparisonAction; |
| 15 | +import com.groupdocs.comparison.changes.ChangeInfo; |
| 16 | +import com.groupdocs.comparison.changes.ComparisonAction; |
| 17 | +import com.groupdocs.comparison.changes.Rectangle; |
| 18 | +import com.groupdocs.comparison.common.PageImage; |
| 19 | +import com.groupdocs.comparison.common.TypeChanged; |
12 | 20 | import com.groupdocs.comparison.common.compareresult.ICompareResult; |
13 | 21 | import com.groupdocs.comparison.common.comparisonsettings.ComparisonSettings; |
14 | 22 | import com.groupdocs.comparison.common.comparisonsettings.DetailLevel; |
@@ -350,4 +358,70 @@ public static void propertiesOfICompareResult(String sourceFile, String targetFi |
350 | 358 | result.updateChanges(changes); |
351 | 359 | //ExEnd:propertiesOfICompareResult |
352 | 360 | } |
| 361 | + |
| 362 | + //Get Coordinates of Specific Changes in Result Document |
| 363 | + public static void getCoordinatesOfSpecificChangesInResultDocument(String sourceFile, String targetFile) throws Exception{ |
| 364 | + //ExStart:getCoordinatesOfSpecificChangesInResultDocument |
| 365 | + ComparisonSettings comparisonSettings = new ComparisonSettings(); |
| 366 | + comparisonSettings.setStyleChangeDetection(true); |
| 367 | + //this setting specify that we want to have change coordinates |
| 368 | + comparisonSettings.setCalculateComponentCoordinates(true); |
| 369 | + comparisonSettings.setDetailLevel(DetailLevel.High); |
| 370 | + |
| 371 | + String sourcePath = Utilities.sourcePath + sourceFile; |
| 372 | + String targetPath = Utilities.targetPath + targetFile; |
| 373 | + |
| 374 | + Comparer comparer = new Comparer(); |
| 375 | + ICompareResult result = comparer.compare(sourcePath, targetPath, comparisonSettings); |
| 376 | + result.saveDocument(Utilities.outputFileName(extension)); |
| 377 | + |
| 378 | + List<PageImage> resultImages = comparer.convertToImages(Utilities.resultImagePath); |
| 379 | + final ChangeInfo[] changes = result.getChanges(); |
| 380 | + |
| 381 | + // Below the one of cases how we could use changes coordinates. |
| 382 | + // We are passing through pages object and draw a rectangle in the coordinates of changes |
| 383 | + for (PageImage pageImage : resultImages) { |
| 384 | + final InputStream pageStream = pageImage.getPageStream(); |
| 385 | + final BufferedImage bufferedImage = ImageIO.read(pageStream); |
| 386 | + final Graphics graphics = bufferedImage.getGraphics(); |
| 387 | + for (ChangeInfo changeInfo : changes) { |
| 388 | + final Rectangle rectangle = changeInfo.getBox(); |
| 389 | + //if something was Inserted draw a Blue rectange |
| 390 | + if (changeInfo.getType() == TypeChanged.Inserted) { |
| 391 | + graphics.setColor(Color.BLUE); |
| 392 | + graphics.drawRect((int) rectangle.getX(), (int) rectangle.getY(), (int) rectangle.getWidth(), (int) rectangle.getHeight()); |
| 393 | + } |
| 394 | + //if something was Deleted draw a Red rectange |
| 395 | + if (changeInfo.getType() == TypeChanged.Deleted) { |
| 396 | + |
| 397 | + graphics.setColor(Color.RED); |
| 398 | + graphics.drawRect((int) rectangle.getX(), (int) rectangle.getY(), (int) rectangle.getWidth(), (int) rectangle.getHeight()); |
| 399 | + } |
| 400 | + //if something was Changes draw a Green rectange |
| 401 | + if (changeInfo.getType() == TypeChanged.StyleChanged) { |
| 402 | + graphics.setColor(Color.GREEN); |
| 403 | + graphics.drawRect((int) rectangle.getX(), (int) rectangle.getY(), (int) rectangle.getWidth(), (int) rectangle.getHeight()); |
| 404 | + } |
| 405 | + } |
| 406 | + graphics.dispose(); |
| 407 | + pageStream.close(); |
| 408 | + } |
| 409 | + |
| 410 | + //ExEnd:getCoordinatesOfSpecificChangesInResultDocument |
| 411 | + } |
| 412 | + |
| 413 | + //Sensitive comparison of the documents |
| 414 | + public static void sensitiveComparisonOfDocuments(String sourceFile, String targetFile) throws Exception{ |
| 415 | + //ExStart:sensitiveComparisonOfDocuments |
| 416 | + String sourcePath = Utilities.sourcePath + sourceFile; |
| 417 | + String targetPath = Utilities.targetPath + targetFile; |
| 418 | + |
| 419 | + ComparisonSettings comparisonSettings = new ComparisonSettings(); |
| 420 | + comparisonSettings.setSensitivityOfComparison(100); |
| 421 | + |
| 422 | + Comparer comparer = new Comparer(); |
| 423 | + ICompareResult result = comparer.compare(sourcePath, targetPath, comparisonSettings); |
| 424 | + result.saveDocument(Utilities.outputFileName(extension)); |
| 425 | + //ExEnd:sensitiveComparisonOfDocuments |
| 426 | + } |
353 | 427 | } |
0 commit comments