No result when comparing PDFs with GroupDocs.Comparison for Java


#1

I’m testing out the comparison functionality with GroupDocs.Comparison specifically when comparing PDFs. I put together a quick test and the Words comparison works fine but the PDF comparison does not generate an error but also does not produce a document. Is there something I’m missing? I’m following the examples and these are pretty trivial tests. You can run the test by just running ./gradlew run



#2

Hi Cking,


Thanks for posting the query.
I’m following the examples
Can you please tell us, which example project you are using? Did you get example project from here?

Best Wishes

#3

Yes, if you click the link you provided and go into the Examples and the file PdfDocumentsComparison.java you will see a method:


<table class=“highlight tab-size js-file-line-container” data-tab-size=“8” style=“box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto, Helvetica, Arial, sans-serif, “Apple Color Emoji”, “Segoe UI Emoji”, “Segoe UI Symbol”; font-size: 14px; background-color: rgb(255, 255, 255);”> <td id=“LC14” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> /* <td id=“L15” class=“blob-num js-line-number” data-line-number=“15” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC15” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> * Comparing two pdf documents from streams, with settings and saving output <td id=“L16” class=“blob-num js-line-number” data-line-number=“16” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC16” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> * to a resultant file <td id=“L17” class=“blob-num js-line-number” data-line-number=“17” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC17” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> */ <td id=“L18” class=“blob-num js-line-number” data-line-number=“18” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC18” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> public static void ComparePdfFromStreamToFile(String sourceFile, String targetFile) throws Throwable { <td id=“L19” class=“blob-num js-line-number” data-line-number=“19” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC19” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> //ExStart:ComparePdfFromStreamToFile <td id=“L20” class=“blob-num js-line-number” data-line-number=“20” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC20” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> // Create two streams of textFiles <td id=“L21” class=“blob-num js-line-number” data-line-number=“21” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC21” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> InputStream sourceStream = Utilities.sourceStream(sourceFile); <td id=“L22” class=“blob-num js-line-number” data-line-number=“22” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC22” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> InputStream targetStream = Utilities.targetStream(targetFile); <td id=“L23” class=“blob-num js-line-number” data-line-number=“23” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC23” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> // Create instance of GroupDocs.Comparison.Comparison and call method <td id=“L24” class=“blob-num js-line-number” data-line-number=“24” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC24” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> // Compare. <td id=“L25” class=“blob-num js-line-number” data-line-number=“25” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC25” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> Comparison comparison = new Comparison(); <td id=“L26” class=“blob-num js-line-number” data-line-number=“26” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC26” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> InputStream result = comparison.compare(sourceStream, targetStream, Utilities.outputFileName(extension), <td id=“L27” class=“blob-num js-line-number” data-line-number=“27” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC27” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> ComparisonType.Pdf, new PdfComparisonSettings()); <td id=“L28” class=“blob-num js-line-number” data-line-number=“28” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC28” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> //ExEnd:ComparePdfFromStreamToFile <td id=“L29” class=“blob-num js-line-number” data-line-number=“29” style=“box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-image: initial; border-width: 0px 1px 0px 0px;”><td id=“LC29” class=“blob-code blob-code-inner js-file-line” style=“box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre;”> }

That is functionally identical to the method I provided. The code example (TestRunner.java) is only 40 lines long so not much to review, but the method:

public static void comparePdf() throws Exception {
Comparison comp = new Comparison();
InputStream oldDoc = TestRunner.class.getResourceAsStream(“original.pdf”);
InputStream newDoc = TestRunner.class.getResourceAsStream(“updated.pdf”);

PdfComparisonSettings settings = new PdfComparisonSettings();

comp.compare(oldDoc, newDoc, “result.pdf”, ComparisonType.Pdf, settings);

}
Is equivalent in all ways to the one from the examples.

#4

Hi Cking,


We are able to reproduce this issue at our end as well (output Pdf document is not generated with gradle). Hence, we have logged it in our internal issue tracking system. As we get any update from the concerned team, we will apprise you.

Kind Regards

#5

Any updates here? These issues are currently holding up our purchasing decision so I’m just trying to get an update on if and when this may be fixed.


#6

Hi Cking,


We have asked about the progress/state of this issue from the concerned team. Hence, as we get any update from them, we will notify you. Please stay tuned.
We appreciate your patience.

Many Thanks