}
protected static final boolean comparePdf(String inputFileName1, String inputFileName2, String outputFileName) throws Exception{
// Comparison Routine
boolean equal = true;
PdfReader reader1 = new PdfReader(inputFileName1);
PdfReader reader2 = new PdfReader(inputFileName2);
FileOutputStream outputStream = new FileOutputStream(outputFileName);
if(reader1.getFileLength() != reader2.getFileLength()) {
equal = false;
String dataToWrite = "Files are of different length. One is " + reader1.getFileLength() + " and the other is " + reader2.getFileLength() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
outputStream.write(dataToWrite.getBytes());
} else if(reader1.getNumberOfPages() != reader2.getNumberOfPages()) {
equal = false;
String dataToWrite = "Number of pages are different in both files. One has " + reader1.getNumberOfPages() + " and the other has " + reader2.getNumberOfPages() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
outputStream.write(dataToWrite.getBytes());
} else {
for(int i=1;i<=reader1.getNumberOfPages();i++) {
byte[] data1 = reader1.getPageContent(i);
byte[] data2 = reader2.getPageContent(i);
for(int j = 0; i < data1.length; i ++) {
if(data1[j] != data2[j]) {
equal = false;
String dataToWrite = "Page #" + i + "has different data. File 1 has" + data1[j] + "Whereas File 2 has " + data2[j] + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
outputStream.write(dataToWrite.getBytes());
}
}
}
}
if(equal) {
String dataToWrite = "Files are identical";//$NON-NLS-1$
outputStream.write(dataToWrite.getBytes());
}
outputStream.flush();
outputStream.close();
reader1.close();
reader2.close();
return equal;
}