Katalon PDF Comparison


#1

Hi Katalon Team,

I am planning to start working on Katalon studio tool but before starting I want to check is there any functionality provided by katalon to compare two pdf files if not can we use plug-ins like “BeyondCompare” with Katalon for comparison of two pdf files?

Thanks,
Shubham Joshi


#2

Hi @shubhamjoshi12

Katalon doesn’t offer any native method to do what you’re asking for. Sorry about that.

@kazurayam, I vaguely remember you built something related to this, or was it image comparison ?

Regards !


#3

You can use Groovy to call BeyondCompare CLI.


#4

You can also import and use this lib:

It’s use is pretty straight forward, and provides a good visual comparison.


#5

Hello,

try with this util


#6

hi,

I tried and works fine, tried only without any images in pdf file

My pdf files content

This is first demo pdf page

human
cat
dog
snake
worm
eagle
rabbit

This is second demo pdf page

human
cat
dog
squirrel
worm
eagle
rabbit

.jar added to Driver folder

in test class
import com.testautomationguru.utility.PDFUtil;

PDFUtil pdfUtil = new PDFUtil();

// returns the pdf content from page number 1
String file_1 = pdfUtil.getText("C:/Users/xxxx/Desktop/data/file1.pdf",1);
String file_2 = pdfUtil.getText("C:/Users/xxxx/Desktop/data/file2.pdf",1);

def diff1 = CustomKeywords.'readPdfFile.verifyPdfContent.findNotMatching'(file_1, file_2)
def diff2 = CustomKeywords.'readPdfFile.verifyPdfContent.findNotMatching'(file_2, file_1)

println "pages have differences file1 have words "+diff1+ " which are not in file2, file2 instead have "+diff2
pages have differences file1 have words [first, snake] which are not in file2, file2 instead have [second, squirrel]


Custom Keyword
	@Keyword
	public List<String> findNotMatching(String sourceStr, String anotherStr){
		StringTokenizer at = new StringTokenizer(sourceStr, " ");
		StringTokenizer bt = null;
		int i = 0, token_count = 0;
		String token = null;
		boolean flag = false;
		List<String> missingWords = new ArrayList<String>();
		while (at.hasMoreTokens()) {
			token = at.nextToken();
			bt = new StringTokenizer(anotherStr, " ");
			token_count = bt.countTokens();
			while (i < token_count) {
				String s = bt.nextToken();
				if (token.equals(s)) {
					flag = true;
					break;
				} else {
					flag = false;
				}
				i++;
			}
			i = 0;
			if (flag == false)
				missingWords.add(token);
		}
		return missingWords;
	}