This sample class needs the CustomResultHandler.java file.

/*
  i-net software provides programming examples for illustration only, without warranty
  either expressed or implied, including, but not limited to, the implied warranties
  of merchantability and/or fitness for a particular purpose. This programming example
  assumes that you are familiar with the programming language being demonstrated and
  the tools used to create and debug procedures. i-net software support professionals
  can help explain the functionality of a particular procedure, but they will not modify
  these examples to provide added functionality or construct procedures to meet your
  specific needs.
  © i-net software 2011
*/
 
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 PDF files with a custom result handler.
 */
public class CompareTwoFilesWithCustomHandler {
 
    public static void main( String[] args ) {
        if (args == null || args.length != 2) {
            System.out.println( "Usage: CompareTwoFilesWithCustomHandler <PDF-File1> <PDF-File2>" );
            System.exit(1);
        }
        File referenceFile = new File( args[0] ); // first PDF file
        File currentFile   = new File( args[1] ); // second PDF file
 
        // Configure i-net PDFC
        IConfiguration configuration = ConfigurationFactory.getConfiguration();
        configuration.putObject( PDFCProperty.CREATE_DIFFIMAGES, Boolean.TRUE ); // create PNG image for each page of the PDF file with differences
        configuration.putObject( PDFCProperty.CREATE_ORIGIMAGES, Boolean.TRUE ); // create PNG image for each page with the original content 
 
        // Configure Log Output
        Logger logger = Logger.getRootLogger();
        logger.addAppender( new ConsoleAppender( new SimpleLayout() ) );
        IResultHandler resultHandler =  new CustomResultHandler( configuration );
 
        // Compare PDF files
        (new BatchRunner( configuration, resultHandler )).runComparison( referenceFile, currentFile );
 
        // Create Custom Result Handler to use it's additional functionality
        CustomResultHandler customResultHandler = (CustomResultHandler)resultHandler;
 
        int reportCount = customResultHandler.getResultCount();
        logger.debug( "reportCount: " + reportCount );
        String referenceReportName = customResultHandler.getName( 0 );
        logger.debug( "referenceReportName: " + referenceReportName );
 
        int count = customResultHandler.getDifferenceCount( 0 );
        logger.debug( "difference count: " + count );
 
        String diffDescription = customResultHandler.getDifferenceDescription( 0 );
        logger.debug( "diffDescription: " + diffDescription );
 
        boolean theSame = customResultHandler.isFilesIdentical( 0 );
        logger.debug( "files identical: " + theSame );        
    }
}
 

© Copyright 1996 - 2012, i-net software; All Rights Reserved.