Package com.inet.pdfc
Class PDFComparer
- java.lang.Object
-
- com.inet.pdfc.PDFComparer
-
public class PDFComparer extends java.lang.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 Summary
Constructors Constructor Description PDFComparer()
Creates an empty comparer instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PDFComparer
addPresenter(BasePresenter presenter)
Adds a Presenter to thisPDFComparer
.
A presenter is responsible to 'present' the comparison result, like print found differences on the console or create difference images.void
batchCompare(DirectoryPdfSource directory1, DirectoryPdfSource directory2)
Compare the two given directories, always comparingPdfSources
with the same name.void
batchCompare(java.io.File directory1, java.io.File directory2)
Compare the two given directories, always comparing document files with the same name.ResultModel
compare(PdfSource pdf1, PdfSource pdf2)
Compare the two given documents located anywhere.ResultModel
compare(java.io.File document1, java.io.File document2)
Compare the two given PDF-Files located on the file system.java.util.concurrent.CompletableFuture<ResultModel>
compareAsync(PdfSource document1, PdfSource document2)
Asynchronously compares the two given documents.static java.util.List<java.lang.String>
getAvailableCompareModeKeys()
Returns the keys of all compare modes that are available to the application.static java.util.List<java.lang.String>
getAvailableFilterKeys()
Returns the keys of all filters that are available to the application.java.util.List<PresenterExceptionData>
getPresenterExceptions()
Return the exceptions that occurred during the comparison which have not led to an interruption of the comparison.protected boolean
isCreateTextSelectionData()
Defines whether the comparer creates theTextInfoImpl
data for theResultModel
as well.PDFComparer
setProfile(IProfile profile)
Set the profile to use with thisPDFComparer
.
The profile determines which elements must be compared, how large the tolerance must be and other options.PDFComparer
setProfile(java.lang.String profileID)
Set the profile to use with thisPDFComparer
.
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 callingDefaultProfileID.getAvailableProfileIDs()
.PDFComparer
setSettings(Settings settings)
Defines the visibility for difference option.void
setVisibleDifferences(DiffGroup.GroupType... differenceType)
Deprecated.As of i-net PDFC 4.3, usesetSettings( Settings setting)
insteadvoid
setVisibleHighlights(java.lang.String... filterType)
Deprecated.As of i-net PDFC 4.3, usesetSettings( Settings setting)
instead
-
-
-
Constructor Detail
-
PDFComparer
public PDFComparer() throws java.lang.RuntimeException, com.inet.pdfc.generator.InvalidLicenseException
Creates an empty comparer instance. CallsetProfile(IProfile)
to configure the comparer,addPresenter(BasePresenter)
to add output modules and start the comparison withcompare(File, File)
orbatchCompare(File, File)
- Throws:
java.lang.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 Detail
-
setProfile
public PDFComparer setProfile(IProfile profile)
Set the profile to use with thisPDFComparer
.
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(java.lang.String profileID) throws java.lang.IllegalArgumentException
Set the profile to use with thisPDFComparer
.
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 callingDefaultProfileID.getAvailableProfileIDs()
. All Available default profiles can be listed byDefaultProfileID.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:
java.lang.IllegalArgumentException
- thrown if no such profile could be found either by ID or name.- Since:
- i-net PDFC 4.0
- See Also:
DefaultProfileID
-
addPresenter
public PDFComparer addPresenter(BasePresenter presenter)
Adds a Presenter to thisPDFComparer
.
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:
ConsolePresenter
,DifferencesImagePresenter
,DifferencesPDFPresenter
-
compare
public ResultModel compare(java.io.File document1, java.io.File document2) throws PdfcException
Compare the two given PDF-Files located on the file system.
This method is blocking! UsecompareAsync(PdfSource, PdfSource)
for a non-blocking comparison.- Parameters:
document1
- the first document to compare, make sure to have reader plugin for the type of documentdocument2
- 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 errorjava.lang.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! UsecompareAsync(PdfSource, PdfSource)
for a non-blocking comparison.- Parameters:
pdf1
- the first document to compare, make sure to have reader plugin for the type of documentpdf2
- 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(java.io.File directory1, java.io.File directory2)
Compare the two given directories, always comparing document files with the same name.
This method is blocking! UsecompareAsync(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:
java.lang.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 comparingPdfSources
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 theTextInfoImpl
data for theResultModel
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 theResultPage
s 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, usesetSettings( Settings setting)
insteadDefines which differences types will be visible in the comparison output. This method will forward the settings to theResultModel.setVisible(boolean, VisibilitySetting...)
method.
Please note, that the setting forDiffGroup.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(java.lang.String... filterType)
Deprecated.As of i-net PDFC 4.3, usesetSettings( Settings setting)
insteadDefines 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 java.util.concurrent.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 documentdocument2
- 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:
java.lang.IllegalStateException
- if the same comparer is used to start several async comparisons- Since:
- 4.0
-
getAvailableCompareModeKeys
public static java.util.List<java.lang.String> getAvailableCompareModeKeys()
Returns the keys of all compare modes that are available to the application. The returned values can be used as values for thePDFCProperty.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 java.util.List<java.lang.String> getAvailableFilterKeys()
Returns the keys of all filters that are available to the application. The returned values can be used as values for thePDFCProperty.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 java.util.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
-
-