@@ -362,6 +362,34 @@ public String compareVisually(String outPdf, String cmpPdf, String outPath, Stri
362
362
return compareVisually (outPath , differenceImagePrefix , ignoredAreas );
363
363
}
364
364
365
+ /**
366
+ * Compares two PDF documents by content starting from page dictionaries and then recursively comparing
367
+ * corresponding objects which are referenced from them. You can roughly imagine it as depth-first traversal
368
+ * of the two trees that represent pdf objects structure of the documents.
369
+ * <p>
370
+ * Unlike {@link #compareByCatalog(PdfDocument, PdfDocument)} this method performs content comparison page by page
371
+ * and doesn't compare the tag structure, acroforms and all other things that doesn't belong to specific pages.
372
+ * <br>
373
+ * When comparison by content is finished, if any differences were found, visual comparison is automatically started.
374
+ * For more info see {@link #compareVisually(String, String, String, String)}.
375
+ * For this overload, differenceImagePrefix value is generated using diff_%outPdfFileName%_ format.
376
+ * <p>
377
+ * For more explanations about what is outPdf and cmpPdf see last paragraph of the {@link CompareTool}
378
+ * class description.
379
+ * @param outPdf the absolute path to the output file, which is to be compared to cmp-file.
380
+ * @param cmpPdf the absolute path to the cmp-file, which is to be compared to output file.
381
+ * @param outPath the absolute path to the folder, which will be used to store image files for visual comparison.
382
+ * @return string containing text report of the encountered content differences and also list of the pages that are
383
+ * visually different, or null if there are no content and therefore no visual differences.
384
+ * @throws InterruptedException if the current thread is interrupted by another thread while it is waiting
385
+ * for ghostscript or imagemagic processes, then the wait is ended and an {@link InterruptedException} is thrown.
386
+ * @throws IOException is thrown if any of the input files are missing or any of the auxiliary files
387
+ * that are created during comparison process wasn't possible to be created.
388
+ */
389
+ public String compareByContent (String outPdf , String cmpPdf , String outPath ) throws InterruptedException , IOException {
390
+ return compareByContent (outPdf , cmpPdf , outPath , null , null , null , null );
391
+ }
392
+
365
393
/**
366
394
* Compares two PDF documents by content starting from page dictionaries and then recursively comparing
367
395
* corresponding objects which are referenced from them. You can roughly imagine it as depth-first traversal
@@ -381,8 +409,10 @@ public String compareVisually(String outPdf, String cmpPdf, String outPath, Stri
381
409
* @param differenceImagePrefix file name prefix for image files with marked visual differences if there is any.
382
410
* @return string containing text report of the encountered content differences and also list of the pages that are
383
411
* visually different, or null if there are no content and therefore no visual differences.
384
- * @throws InterruptedException
385
- * @throws IOException
412
+ * @throws InterruptedException if the current thread is interrupted by another thread while it is waiting
413
+ * for ghostscript or imagemagic processes, then the wait is ended and an {@link InterruptedException} is thrown.
414
+ * @throws IOException is thrown if any of the input files are missing or any of the auxiliary files
415
+ * that are created during comparison process wasn't possible to be created.
386
416
*/
387
417
public String compareByContent (String outPdf , String cmpPdf , String outPath , String differenceImagePrefix ) throws InterruptedException , IOException {
388
418
return compareByContent (outPdf , cmpPdf , outPath , differenceImagePrefix , null , null , null );
@@ -472,8 +502,10 @@ public String compareByContent(String outPdf, String cmpPdf, String outPath, Str
472
502
* @param cmpPass password for the encrypted document specified by the cmpPdf absolute path.
473
503
* @return string containing text report of the encountered content differences and also list of the pages that are
474
504
* visually different, or null if there are no content and therefore no visual differences.
475
- * @throws InterruptedException
476
- * @throws IOException
505
+ * @throws InterruptedException if the current thread is interrupted by another thread while it is waiting
506
+ * for ghostscript or imagemagic processes, then the wait is ended and an {@link InterruptedException} is thrown.
507
+ * @throws IOException is thrown if any of the input files are missing or any of the auxiliary files
508
+ * that are created during comparison process wasn't possible to be created.
477
509
*/
478
510
public String compareByContent (String outPdf , String cmpPdf , String outPath , String differenceImagePrefix , Map <Integer , List <Rectangle >> ignoredAreas , byte [] outPass , byte [] cmpPass ) throws InterruptedException , IOException {
479
511
init (outPdf , cmpPdf );
@@ -830,8 +862,17 @@ private String compareVisually(String outPath, String differenceImagePrefix, Map
830
862
if (!(new File (gsExec ).canExecute ())) {
831
863
throw new CompareToolExecutionException (new File (gsExec ).getAbsolutePath () + " is not an executable program" );
832
864
}
833
- if (!outPath .endsWith ("/" ))
865
+ if (!outPath .endsWith ("/" )) {
834
866
outPath = outPath + "/" ;
867
+ }
868
+ if (differenceImagePrefix == null ) {
869
+ String fileBasedPrefix = "" ;
870
+ if (outPdfName != null ) { // should always be initialized by this moment
871
+ fileBasedPrefix = outPdfName + "_" ;
872
+ }
873
+ differenceImagePrefix = "diff_" + fileBasedPrefix ;
874
+ }
875
+
835
876
prepareOutputDirs (outPath , differenceImagePrefix );
836
877
837
878
System .out .println ("Comparing visually.........." );
@@ -1092,7 +1133,7 @@ private void loadPagesFromReader(PdfDocument doc, List<PdfDictionary> pages, Lis
1092
1133
}
1093
1134
}
1094
1135
1095
- private void compareDocumentsEncryption (PdfDocument outDocument , PdfDocument cmpDocument , CompareResult compareResult ) throws IOException {
1136
+ private void compareDocumentsEncryption (PdfDocument outDocument , PdfDocument cmpDocument , CompareResult compareResult ) {
1096
1137
PdfDictionary outEncrypt = outDocument .getTrailer ().getAsDictionary (PdfName .Encrypt );
1097
1138
PdfDictionary cmpEncrypt = cmpDocument .getTrailer ().getAsDictionary (PdfName .Encrypt );
1098
1139
0 commit comments