
This sample class needs the CustomResultHandler.java file.
package samples; import java.io.File; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import com.inet.pdfc.config.ConfigurationFactory; import com.inet.pdfc.config.IConfiguration; import com.inet.pdfc.config.PDFCProperty; import com.inet.pdfc.results.IResultHandler; import com.inet.pdfc.runner.BatchRunner; /** * This sample demonstrates how you can compare two folder * containing PDF files with pairwise identical names. */ public class CompareTwoFoldersWithCustomHandler { /** * @param args */ public static void main( String[] args ) { // Configure Log Output Logger logger = Logger.getRootLogger(); logger.addAppender( new ConsoleAppender( new SimpleLayout() ) ); // Check command line arguments if (args == null || args.length != 2) { logger.error( "Usage: CompareTwoFilesWithCustomHandler <folder1> <folder2>" ); System.exit(1); } File referenceFileDir = new File( args[0] ); // first Folder File currentFileDir = new File( args[1] ); // second Folder if( !referenceFileDir.isDirectory() || !currentFileDir.isDirectory() ) { logger.error( "Directories defined through command line parameters must exist" ); System.exit(1); } // Configure i-net PDFC IConfiguration configuration = ConfigurationFactory.getConfiguration(); configuration.putObject( PDFCProperty.CREATE_DIFFIMAGES, Boolean.FALSE ); // don't create PNG image for each page of the PDF file with differences configuration.putObject( PDFCProperty.CREATE_ORIGIMAGES, Boolean.FALSE ); // don't create PNG image for each page with the original content IResultHandler resultHandler = new CustomResultHandler( configuration ); // Compare Folders (new BatchRunner( configuration, resultHandler )).runComparison( referenceFileDir, currentFileDir ); // The same Custom Result Handler can be used for File- and for Folder- Compare CustomResultHandler customResultHandler = (CustomResultHandler)resultHandler; int fileCount = customResultHandler.getResultCount(); logger.debug( "number of file compare results: " + fileCount ); int differentFileCount = 0; for( int i=0; i< fileCount; i++ ) { String referenceFileName = customResultHandler.getName( i ); logger.debug(""); logger.debug( "File name: " + referenceFileName ); logger.debug( "-------------------------------" ); int differenceCount = customResultHandler.getDifferenceCount( i ); logger.debug( "number of differences: " + differenceCount ); if( differenceCount != 0 ) { differentFileCount++; } } if( fileCount != 0 ) { logger.debug(""); if( differentFileCount == 0 ) { logger.debug( "Files in folders " + referenceFileDir.getName() + " and " + currentFileDir.getName() + " are identical" ); } else { logger.debug( "Different files count: " + differentFileCount ); } } } }