Skip to content

Horizontal compare - #93

Merged
finsterwalder merged 7 commits into
red6:masterfrom
v3g3t4x:horizontal_compare
Sep 14, 2026
Merged

finsterwalder merged 7 commits into
red6:masterfrom
v3g3t4x:horizontal_compare

Conversation

@v3g3t4x

@v3g3t4x v3g3t4x commented Mar 12, 2021

Copy link
Copy Markdown
Contributor

Added horizontal compare.
Gived 2 pdf generate a third pdf where for each page you can find on the left the page of first pdf and on the right the page of the second pdf.
Here an example on how use it...use setEnableHorizontalCompareOutput..

PdfComparator compare = new PdfComparator("input/input1.pdf", "input/input2.pdf");
boolean flagLeftRight = true;
compare.headerLeft = "LEFT";
compare.headerRight = "RIGHT";
compare.withEnvironment(new SimpleEnvironment().setActualColor(Color.red).setParallelProcessing(true)
.setMaxImageSize(100000).setDocumentCacheSize(0).setOverallTimeout(15)
.setExpectedColor(Color.CYAN).setAddEqualPagesToResult(true).setDPI(DPI)
.setEnableHorizontalCompareOutput(flagLeftRight).setAllowedDiffInPercent(pixel));
CompareResult result = compare.compare();

@nilimapradipm

Copy link
Copy Markdown

Thanks a lot

@Greg0816

Greg0816 commented Jul 3, 2026

Copy link
Copy Markdown

I would love this feature!
I have to give the difference to our specialised department for review, but it's hard for them to read the squashed pixels and it's tedious for me to fetch the 'actual PDF' from within our systems.

@v3g3t4x

v3g3t4x commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

I would love this feature! I have to give the difference to our specialised department for review, but it's hard for them to read the squashed pixels and it's tedious for me to fetch the 'actual PDF' from within our systems.

How I can help you?

@Greg0816

Greg0816 commented Jul 6, 2026

Copy link
Copy Markdown

I would love this feature! I have to give the difference to our specialised department for review, but it's hard for them to read the squashed pixels and it's tedious for me to fetch the 'actual PDF' from within our systems.

How I can help you?

I want to push your PR. Your feature would be very helpful for me. That's all :)

@v3g3t4x

v3g3t4x commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I would love this feature! I have to give the difference to our specialised department for review, but it's hard for them to read the squashed pixels and it's tedious for me to fetch the 'actual PDF' from within our systems.

How I can help you?

I want to push your PR. Your feature would be very helpful for me. That's all :)

I don't know why PR is still open. You can contact manteiner of repo.

@finsterwalder

Copy link
Copy Markdown
Collaborator

Hi there,
this repo is not under very active development anymore. I hardly find time to work on it.
The PR has some flaws in code quality IMHO and is inconsistent to the existing code in some ways.
I didn't have the time to do a proper review or rework of the code. Sorry.
Maybe I find the time during the next two weeks.


@Override
public int getNrOfImagesToCache() {
return config.getInt("imageCacheSizeCount");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be set to a fixed value. Revert to the previous code, please


@Override
public boolean getEnableHorizontalCompareOutput() {
return false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be a fixed value but should be read from the config instead, so it's configurable via a config file

private Integer dpi;
private Boolean addEqualPagesToResult;
private Boolean failOnMissingIgnoreFile;
private Boolean enableHorizontalCompareOutput=false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be initialized to false here.

}

public boolean getEnableHorizontalCompareOutput() {
return enableHorizontalCompareOutput;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should include fallback handling to be consistent with the config chain.

Utilities.shutdownAndAwaitTermination(swapExecutor, "Swap");
try {
LOG.trace("Merging...");
LOG.info("Merging...");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave this at trace level to reduce logging noise for normal users

Comment on lines +128 to +130
if(this.environment.getEnableHorizontalCompareOutput()) {
this.addPageWithHorizontalCompare(diffCalculator, pageIndex, expectedImage, actualImage, diffImage);
}else {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same formatting/spacing as the rest of the code

@@ -0,0 +1,61 @@
package x.team.tool;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a package in de.red6.pdfcompare

Comment on lines +1 to +33
package x.team.poc;

import java.awt.Color;

import de.redsix.pdfcompare.CompareResult;
import de.redsix.pdfcompare.PdfComparator;
import de.redsix.pdfcompare.env.SimpleEnvironment;

public class POC {

public static void main(String[] args) {
try {

PdfComparator compare = new PdfComparator("input/expected.pdf", "input/actual.pdf")
.withEnvironment(new SimpleEnvironment().setActualColor(Color.red)
.setExpectedColor(Color.white).setAddEqualPagesToResult(true)
.setEnableHorizontalCompareOutput(true));

CompareResult result = compare.compare();
result .writeTo("output/diffOutput");
if (result.isNotEqual()) {
System.out.println("Ho trovato differenza!");
}
if (result.isEqual()) {
System.out.println("Non ho trovato nessuna differenza!");
}
result.getDifferences();
} catch (Exception e) {
e.printStackTrace();
}
}

}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write a proper integration test for this scenarios.
English in code and comments only please.

}

@Override
public void addPageWithHorizontalCompare(PageDiffCalculator diffCalculator, int pageIndex,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not unit tested. Please write tests for it.


public class MergeImages {

public ImageWithDimension mergeOnLeft(ImageWithDimension left, ImageWithDimension right, String headerLeft,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is not unit tested. Please write tests for it.

@finsterwalder

Copy link
Copy Markdown
Collaborator

@v3g3t4x I quickly added some immediate findings. Could you clean those up please?
Then I will look again in more detail. Thank you!

Comment on lines -99 to +120
LOG.info("Differences found at { page: {}, x1: {}, y1: {}, x2: {}, y2: {} }", page + 1, diffAreaX1, diffAreaY1, diffAreaX2,
LOG.debug("Differences found at { page: {}, x1: {}, y1: {}, x2: {}, y2: {} }", page + 1, diffAreaX1, diffAreaY1, diffAreaX2,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the log level?

Objects.requireNonNull(actualImage, "actualImage is null");
Objects.requireNonNull(diffImage, "diffImage is null");
this.hasDifferenceInExclusion |= diffCalculator.differencesFoundInExclusion();
diffPercentages.put(pageIndex, diffCalculator.getDifferenceInPercent());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is missing in the else-block.

@Greg0816

Greg0816 commented Jul 7, 2026

Copy link
Copy Markdown

@v3g3t4x I want to support the development, if you wish. Please add me as maintainer to your PR.

edit: Most of the work is done, but i can't push to your PR. I hope we find a solution :)

@finsterwalder

finsterwalder commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

@Greg0816
I'm not at all a Github expert.
But I think there are two ways to approach this:
Either @v3g3t4x gives you access to the existing branch and PR.
But if that does not happen in time, you could simply fork again from @v3g3t4x branch and create a new PR.

@Greg0816

Greg0816 commented Jul 7, 2026

Copy link
Copy Markdown

@Greg0816 I'm not at all a Github expert. But I think there are two ways to approach this: Either @v3g3t4x gives you access to the existing branch and PR. But if that does not happen in time, you could simply fork again from @v3g3t4x branch and create a new PR.

So am i ;-)
Thanks for your advise.

But he did most of the work, so i want to give him the credits.
I'll wait about two more days, otherwise i'll fork.

@Greg0816 Greg0816 mentioned this pull request Jul 14, 2026
@finsterwalder
finsterwalder merged commit 4144a3f into red6:master Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants