Package com.inet.pdfc

Class PDFComparer

java.lang.Object
com.inet.pdfc.PDFComparer

public class PDFComparer extends Object
This is the main entry point when using i-net PDFC API. The PDFComparer can compare two files or folders and allows the user to add presenters to show the result.

Typical Usage:

 File referenceFile = new File( args[0] ); // first document file
 File currentFile = new File( args[1] ); // second document file
 
 IProfile profile = new DefaultProfile();
 profile.putObject( PDFCProperty.CONTINUOUS_COMPARE, Boolean.TRUE );
 
 new PDFComparer().setProfile( profile ).addPresenter( new ConsolePresenter() ).compare( referenceFile, currentFile );
 

Since:
i-net PDFC 3.0
  • Constructor Details

    • PDFComparer

      public PDFComparer() throws RuntimeException, com.inet.pdfc.generator.InvalidLicenseException
      Creates an empty comparer instance. Call setProfile(IProfile) to configure the comparer, addPresenter(BasePresenter) to add output modules and start the comparison with compare(File, File) or batchCompare(File, File)
      Throws:
      RuntimeException - A runtime exception will be thrown here if and only if there is no valid license which grants API permissions.
      com.inet.pdfc.generator.InvalidLicenseException - thrown in case there is no license for i-net PDFC or, if the license is insufficient for the API.
      Since:
      i-net PDFC 3.0
  • Method Details

    • setProfile

      public PDFComparer setProfile(IProfile profile)
      Set the profile to use with this PDFComparer.
      The profile determines which elements must be compared, how large the tolerance must be and other options.
      Parameters:
      profile - the profile to use, must not be null.
      Returns:
      this PDFComparer, allowing additional methods to be called in a chain.
      Since:
      i-net PDFC 4.0
    • setProfile

      public PDFComparer setProfile(String profileID) throws IllegalArgumentException
      Set the profile to use with this PDFComparer.
      The profile determines which elements must be compared, how large the tolerance must be and other options.
      It's recommended to check whether the profile is available first by calling DefaultProfileID.getAvailableProfileIDs(). All Available default profiles can be listed by DefaultProfileID.getAvailableProfileIDs().
      Parameters:
      profileID - the ID or name of the profile to be used. Please note, that the names of default profiles are localized, so use their ID instead.
      Returns:
      this PDFComparer, allowing additional methods to be called in a chain.
      Throws:
      IllegalArgumentException - thrown if no such profile could be found either by ID or name.
      Since:
      i-net PDFC 4.0
      See Also:
    • addPresenter

      public PDFComparer addPresenter(BasePresenter presenter)
      Adds a Presenter to this PDFComparer.
      A presenter is responsible to 'present' the comparison result, like print found differences on the console or create difference images.
      Parameters:
      presenter - the presenter to add, must not be null.
      Returns:
      this PDFComparer, allowing additional methods to be called in a chain.
      Since:
      i-net PDFC 3.0
      See Also:
    • compare

      public ResultModel compare(File document1, File document2) throws PdfcException
      Compare the two given PDF-Files located on the file system.
      This method is blocking! Use compareAsync(PdfSource, PdfSource) for a non-blocking comparison.
      Parameters:
      document1 - the first document to compare, make sure to have reader plugin for the type of document
      document2 - the second document to compare, make sure to have reader plugin for the type of document
      Returns:
      a ResultModel containing result-information about the comparison.
      Throws:
      PdfcException - when comparison faced an error
      IllegalArgumentException - in case document cannot be accessed or is a directory
      Since:
      i-net PDFC 3.0
    • compare

      public ResultModel compare(PdfSource pdf1, PdfSource pdf2) throws PdfcException
      Compare the two given documents located anywhere.
      This method is blocking! Use compareAsync(PdfSource, PdfSource) for a non-blocking comparison.
      Parameters:
      pdf1 - the first document to compare, make sure to have reader plugin for the type of document
      pdf2 - the second document to compare, make sure to have reader plugin for the type of document
      Returns:
      a ResultModel containing result-information about the comparison.
      Throws:
      PdfcException - in case of an internal exception
      Since:
      i-net PDFC 3.0
    • batchCompare

      public void batchCompare(File directory1, File directory2)
      Compare the two given directories, always comparing document files with the same name.
      This method is blocking! Use compareAsync(PdfSource, PdfSource) for a non-blocking comparison.
      Parameters:
      directory1 - the first directory to use, must be a directory.
      directory2 - the second directory to use, must be a directory.
      Throws:
      IllegalArgumentException - thrown in case the directory is not readable or not a directory
      Since:
      i-net PDFC 3.0
    • batchCompare

      public void batchCompare(DirectoryPdfSource directory1, DirectoryPdfSource directory2)
      Compare the two given directories, always comparing PdfSources with the same name.
      Parameters:
      directory1 - the first directory to use, must not be null.
      directory2 - the second directory to use, must not be null.
      Since:
      i-net PDFC 3.0
    • isCreateTextSelectionData

      protected boolean isCreateTextSelectionData()
      Defines whether the comparer creates the TextInfoImpl data for the ResultModel as well. This data may require a large amount of memory depending on the text size. It should only be enabled if the protected method getTextInfos() of the ResultPages is used! Otherwise it's a waste of performance and memory.
      Returns:
      returns false by default
      Since:
      i-net PDFC 3.2
    • setVisibleDifferences

      @Deprecated public void setVisibleDifferences(DiffGroup.GroupType... differenceType)
      Deprecated.
      As of i-net PDFC 4.3, use setSettings(Settings setting) instead
      Defines which differences types will be visible in the comparison output. This method will forward the settings to the ResultModel.setVisible(boolean, VisibilitySetting...) method.
      Please note, that the setting for DiffGroup.GroupType.Sync will be ignored here, as they are internal and to not map to a real differences type.
      Parameters:
      differenceType - the types to set visible; any type which is not in this list will be hidden
      Since:
      i-net PDFC 3.2
    • setVisibleHighlights

      @Deprecated public void setVisibleHighlights(String... filterType)
      Deprecated.
      As of i-net PDFC 4.3, use setSettings(Settings setting) instead
      Defines for which filter types highlights are visible. There will be no highlights for inactive filters or filters not mentioned in this list. So, by default, all highlights are deactivated
      Parameters:
      filterType - the filters to activate the highlights for.
      Since:
      i-net PDFC 4
    • setSettings

      public PDFComparer setSettings(Settings settings)
      Defines the visibility for difference option. For example can be set the visibility for filter highlights or difference group types. Default are all highlights for inactive filters or filters not mentioned in this list. So, by default, all highlights are deactivated Default are all public difference group types visible.
      Parameters:
      settings - the filters to activate the highlights for.
      Returns:
      this PDFComparer, allowing additional methods to be called in a chain.
      Since:
      i-net PDFC 4.3
    • compareAsync

      public CompletableFuture<ResultModel> compareAsync(PdfSource document1, PdfSource document2)
      Asynchronously compares the two given documents.
      Parameters:
      document1 - the first document to compare, make sure to have reader plugin for the type of document
      document2 - the second document to compare, make sure to have reader plugin for the type of document
      Returns:
      a worker object to wait for the result or to cancel the process
      Throws:
      IllegalStateException - if the same comparer is used to start several async comparisons
      Since:
      4.0
    • getAvailableCompareModeKeys

      public static List<String> getAvailableCompareModeKeys()
      Returns the keys of all compare modes that are available to the application. The returned values can be used as values for the PDFCProperty.CONTINUOUS_COMPARE property.
      Compare algorithms are plugins an thus can be removed or deactivated.
      Returns:
      the keys of all compare modes that are available to the application
      Since:
      4.0
    • getAvailableFilterKeys

      public static List<String> getAvailableFilterKeys()
      Returns the keys of all filters that are available to the application. The returned values can be used as values for the PDFCProperty.FILTERS property.
      Filters are plugins an thus can be removed or deactivated. It's recommended to check for valid filters when modifying a profile.d
      Returns:
      the keys of all filters that are available to the application
      Since:
      4.0
    • getPresenterExceptions

      public List<PresenterExceptionData> getPresenterExceptions()
      Return the exceptions that occurred during the comparison which have not led to an interruption of the comparison.
      Returns:
      all exception in the presenters
      Since:
      5.0