public class Comparer extends Object implements com.aspose.ms.System.IDisposable, Closeable
It allows you to compare various types of documents, such as PDF, Word, Excel, PowerPoint, and more.
Example usage:
try (Comparer comparer = new Comparer(sourceFile)) {
comparer.add(targetFile);
CompareOptions compareOptions = new CompareOptions();
compareOptions.setDetectStyleChanges(true);
comparer.compare(resultFile, compareOptions);
}
CompareOptions| Constructor and Description |
|---|
Comparer(ComparerSettings settings)
Initializes new instance of Comparer class with the specified
ComparerSettings. |
Comparer(InputStream document)
Initializes new instance of Comparer class with the specified source document stream.
|
Comparer(InputStream document,
ComparerSettings settings)
Initializes new instance of Comparer class with the specified source document stream and
ComparerSettings. |
Comparer(InputStream document,
LoadOptions loadOptions)
Initializes new instance of Comparer with the specified source document stream and
LoadOptions. |
Comparer(InputStream document,
LoadOptions loadOptions,
ComparerSettings settings)
Initializes new instance of Comparer class with the specified document stream,
LoadOptions and ComparerSettings. |
Comparer(Path filePath)
Initializes new instance of Comparer class with the specified source file path.
|
Comparer(Path filePath,
CompareOptions compareOptions)
Initializes new instance of Comparer with the specified source file path and
LoadOptions. |
Comparer(Path filePath,
ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path and
ComparerSettings. |
Comparer(Path filePath,
LoadOptions loadOptions)
Initializes new instance of Comparer with the specified source file path and
LoadOptions. |
Comparer(Path filePath,
LoadOptions loadOptions,
ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path,
LoadOptions and ComparerSettings. |
Comparer(Path filePath,
LoadOptions loadOptions,
ComparerSettings settings,
CompareOptions compareOptions)
Initializes new instance of Comparer class with the specified source file path,
LoadOptions and ComparerSettings. |
Comparer(String filePath)
Initializes new instance of Comparer class with the specified source file path.
|
Comparer(String filePath,
CompareOptions compareOptions)
Initializes a new instance of the Comparer class with the specified folder path and compare options.
|
Comparer(String filePath,
ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path and
ComparerSettings. |
Comparer(String filePath,
LoadOptions loadOptions)
Initializes new instance of Comparer with the specified source file path and
LoadOptions. |
Comparer(String filePath,
LoadOptions loadOptions,
ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path,
LoadOptions and ComparerSettings. |
Comparer(String filePath,
LoadOptions loadOptions,
ComparerSettings settings,
CompareOptions compareOptions)
Initializes new instance of Comparer class with the specified source file path,
LoadOptions and ComparerSettings. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(InputStream... documents)
Adds the specified target documents to the comparison process.
|
void |
add(InputStream document)
Adds the specified target document to the comparison process.
|
void |
add(InputStream document,
LoadOptions loadOptions)
Adds the specified target document to the comparison process with loading options specified.
|
void |
add(Path... filePaths)
Adds the specified target documents to the comparison process.
|
void |
add(Path filePath)
Adds the specified target document to the comparison process.
|
void |
add(Path filePath,
CompareOptions compareOptions)
Adds the specified target document to the comparison process with loading options specified.
|
void |
add(Path filePath,
LoadOptions loadOptions)
Adds the specified target document to the comparison process with loading options specified.
|
void |
add(String... filePaths)
Adds the specified target documents to the comparison process.
|
void |
add(String filePath)
Adds the specified target document to the comparison process.
|
void |
add(String filePath,
CompareOptions compareOptions)
Adds the specified target document or folder to the comparison process.
|
void |
add(String filePath,
LoadOptions loadOptions)
Adds the specified target document to the comparison process with loading options specified.
|
void |
applyChanges(OutputStream document,
ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
|
void |
applyChanges(OutputStream document,
SaveOptions saveOptions,
ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
|
void |
applyChanges(Path filePath,
ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
|
void |
applyChanges(Path filePath,
SaveOptions saveOptions,
ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
|
void |
applyChanges(String filePath,
ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to result document.
|
void |
applyChanges(String filePath,
SaveOptions saveOptions,
ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
|
void |
close()
Releases resources.
|
Path |
compare()
Compares the specified file with the target documents without saving result with default options.
|
Path |
compare(CompareOptions compareOptions)
Compares the specified file with the target documents without saving result.
|
Path |
compare(OutputStream outputStream)
Compares the specified file with the target documents and writes a comparison result to the output stream.
|
Path |
compare(OutputStream document,
CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the output stream.
|
Path |
compare(OutputStream document,
SaveOptions saveOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
|
Path |
compare(OutputStream outputStream,
SaveOptions saveOptions,
CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided output stream.
|
Path |
compare(Path filePath)
Compares the specified file with the target documents and generates a comparison result.
|
Path |
compare(Path filePath,
CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
|
Path |
compare(Path filePath,
SaveOptions saveOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
|
Path |
compare(Path filePath,
SaveOptions saveOptions,
CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
|
Path |
compare(SaveOptions saveOptions,
CompareOptions compareOptions)
Compares the specified file with the target documents without saving result.
|
Path |
compare(String filePath)
Compares the specified file with the target documents and generates a comparison result.
|
Path |
compare(String filePath,
CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
|
Path |
compare(String filePath,
SaveOptions saveOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
|
Path |
compare(String filePath,
SaveOptions saveOptions,
CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
|
void |
compareDirectory(Path filePath,
CompareOptions compareOptions)
Compares the specified directory with the target directory and saves the comparison result to the provided file path.
|
void |
compareDirectory(String filePath,
CompareOptions compareOptions)
Compares the specified directory with the target directory and saves the comparison result to the provided file path.
|
ChangeInfo[] |
getChanges()
Retrieves an array of
ChangeInfo objects representing the changes detected during the comparison process. |
ChangeInfo[] |
getChanges(GetChangeOptions getChangeOptions)
Retrieves an array of
ChangeInfo objects representing the changes detected during the comparison process. |
String |
getResultString()
Gets result string after comparison (For Text Comparison only).
|
Document |
getSource()
Gets the source document that is being compared.
|
String |
getSourceFolder()
Returns the source folder that is being compared.
|
String |
getTargetFolder()
Returns the target folder that is being compared.
|
List<Document> |
getTargets()
List of target documents to compare with source file.
|
public static final String FILE_PATH
public Comparer(ComparerSettings settings)
ComparerSettings.settings - the settingsComparerSettingspublic Comparer(InputStream document)
Initializes new instance of Comparer class with the specified source document stream.
document - The input stream of the source documentpublic Comparer(InputStream document, ComparerSettings settings)
Initializes new instance of Comparer class with the specified source document stream and ComparerSettings.
document - The input stream of the source documentsettings - The comparer settings to be used for the comparison processComparerSettingspublic Comparer(InputStream document, LoadOptions loadOptions)
Initializes new instance of Comparer with the specified source document stream and LoadOptions.
document - The input stream of the source documentloadOptions - The custom load options to be applied to the documentLoadOptionspublic Comparer(InputStream document, LoadOptions loadOptions, ComparerSettings settings)
Initializes new instance of Comparer class with the specified document stream, LoadOptions and ComparerSettings.
document - The stream with data of a document to be comparedloadOptions - The custom load options to be applied to the documentsettings - The comparer settings to be used for the comparison processLoadOptions,
ComparerSettingspublic Comparer(Path filePath)
Initializes new instance of Comparer class with the specified source file path.
filePath - The path to the source documentpublic Comparer(Path filePath, CompareOptions compareOptions)
Initializes new instance of Comparer with the specified source file path and LoadOptions.
filePath - The path to the source documentcompareOptions - The compare options for folder comparisonLoadOptionspublic Comparer(Path filePath, ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path and ComparerSettings.
filePath - The path to the source documentsettings - The comparer settings to be used for the comparison processComparerSettingspublic Comparer(Path filePath, LoadOptions loadOptions)
Initializes new instance of Comparer with the specified source file path and LoadOptions.
filePath - The path to the source documentloadOptions - The custom load options to be applied to the documentLoadOptionspublic Comparer(Path filePath, LoadOptions loadOptions, ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path, LoadOptions and ComparerSettings.
filePath - The path to the source documentloadOptions - The custom load options to be applied to the documentsettings - The comparer settings to be used for the comparison processLoadOptions,
ComparerSettingspublic Comparer(Path filePath, LoadOptions loadOptions, ComparerSettings settings, CompareOptions compareOptions)
Initializes new instance of Comparer class with the specified source file path, LoadOptions and ComparerSettings.
filePath - The path to the source document or folderloadOptions - The custom load options to be applied to the documentsettings - The comparer settings to be used for the comparison processcompareOptions - The compare options for folder comparisonLoadOptions,
ComparerSettingspublic Comparer(String filePath)
Initializes new instance of Comparer class with the specified source file path.
filePath - The path to the source documentpublic Comparer(String filePath, CompareOptions compareOptions)
Initializes a new instance of the Comparer class with the specified folder path and compare options.
filePath - The path to the source document or foldercompareOptions - The compare options for folder comparisonpublic Comparer(String filePath, ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path and ComparerSettings.
filePath - The path to the source documentsettings - The comparer settings to be used for the comparison processComparerSettingspublic Comparer(String filePath, LoadOptions loadOptions)
Initializes new instance of Comparer with the specified source file path and LoadOptions.
filePath - The path to the source documentloadOptions - The custom load options to be applied to the documentLoadOptionspublic Comparer(String filePath, LoadOptions loadOptions, ComparerSettings settings)
Initializes new instance of Comparer class with the specified source file path, LoadOptions and ComparerSettings.
filePath - The path to the source documentloadOptions - The custom load options to be applied to the documentsettings - The comparer settings to be used for the comparison processLoadOptions,
ComparerSettingspublic Comparer(String filePath, LoadOptions loadOptions, ComparerSettings settings, CompareOptions compareOptions)
Initializes new instance of Comparer class with the specified source file path, LoadOptions and ComparerSettings.
filePath - The path to the source document or folder or text to be comparedloadOptions - The custom load options to be applied to the documentsettings - The comparer settings to be used for the comparison processcompareOptions - The compare options for folder comparisonLoadOptions,
ComparerSettingspublic final void add(InputStream... documents)
Adds the specified target documents to the comparison process.
documents - Streams with data of documents to be comparedpublic final void add(InputStream document)
Adds the specified target document to the comparison process.
document - The stream with data of a document to be comparedpublic final void add(InputStream document, LoadOptions loadOptions)
Adds the specified target document to the comparison process with loading options specified.
document - The stream with data of a document to be comparedloadOptions - The custom load options to be applied to the documentLoadOptionspublic final void add(Path... filePaths)
Adds the specified target documents to the comparison process.
filePaths - Paths to the target documents to be addedpublic final void add(Path filePath)
Adds the specified target document to the comparison process.
filePath - The path to the target document to be addedpublic final void add(Path filePath, CompareOptions compareOptions)
Adds the specified target document to the comparison process with loading options specified.
filePath - The path to the target document or folder to be addedcompareOptions - The options for the comparisonLoadOptionspublic final void add(Path filePath, LoadOptions loadOptions)
Adds the specified target document to the comparison process with loading options specified.
filePath - Path to the target document to be addedloadOptions - The custom load options to be applied to the documentLoadOptionspublic final void add(String... filePaths)
Adds the specified target documents to the comparison process.
filePaths - Paths to the target documents to be addedpublic final void add(String filePath)
Adds the specified target document to the comparison process.
filePath - The path to the target document to be addedpublic void add(String filePath, CompareOptions compareOptions)
filePath - The path to the target document or folder to be addedcompareOptions - The options for the comparisonpublic final void add(String filePath, LoadOptions loadOptions)
Adds the specified target document to the comparison process with loading options specified.
filePath - Path to the target document to be addedloadOptions - The custom load options to be applied to the documentIllegalArgumentException - if filePath is nullLoadOptionspublic final void applyChanges(OutputStream document, ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
document - Result document output streamapplyChangeOptions - The custom apply change options to configure process of applying changesApplyChangeOptionspublic final void applyChanges(OutputStream document, SaveOptions saveOptions, ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
document - Result document output streamsaveOptions - The save options to configure saving result documentapplyChangeOptions - The custom apply change options to configure process of applying changesSaveOptions,
ApplyChangeOptionspublic final void applyChanges(Path filePath, ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
filePath - Result document file pathapplyChangeOptions - The custom apply change options to configure process of applying changesApplyChangeOptionspublic final void applyChanges(Path filePath, SaveOptions saveOptions, ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
filePath - Result document file pathsaveOptions - The save options to configure saving result documentapplyChangeOptions - The custom apply change options to configure process of applying changesSaveOptions,
ApplyChangeOptionspublic final void applyChanges(String filePath, ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to result document.
filePath - Result document file pathapplyChangeOptions - The custom apply change options to configure process of applying changesApplyChangeOptionspublic final void applyChanges(String filePath, SaveOptions saveOptions, ApplyChangeOptions applyChangeOptions)
Accepts or rejects changes and applies them to resultant document.
filePath - Result document file pathsaveOptions - The save options to configure saving result documentapplyChangeOptions - The custom apply change options to configure process of applying changesSaveOptions,
ApplyChangeOptionspublic void close()
Releases resources.
close in interface Closeableclose in interface AutoCloseablepublic final Path compare()
Compares the specified file with the target documents without saving result with default options.
public final Path compare(CompareOptions compareOptions)
Compares the specified file with the target documents without saving result.
compareOptions - The compare options to be used for the comparison processCompareOptionspublic final Path compare(OutputStream outputStream)
Compares the specified file with the target documents and writes a comparison result to the output stream.
Note: In cases when return value is null, use data that was written into outputStream
outputStream - Result document streamoutputStream must be used. In some situations result file's extension can be changedpublic final Path compare(OutputStream document, CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the output stream.
Note: In case return value is null, use data that was written into outputStream.
document - Result document streamcompareOptions - The compare options to be used for the comparison processoutputStream must be used. In some situations result file's extension can be changedCompareOptionspublic final Path compare(OutputStream document, SaveOptions saveOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
Note: In case return value is null, use data that was written into outputStream
document - Result document streamsaveOptions - Save optionsoutputStream must be used. In some situations result file's extension can be changedSaveOptionspublic final Path compare(OutputStream outputStream, SaveOptions saveOptions, CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided output stream.
Note: In case return value is null, use data that was written into outputStream
outputStream - Result document streamsaveOptions - The save options to be used for the saving the result documentcompareOptions - The compare options to be used for the comparison processoutputStream must be used. In some situations result file's extension can be changedSaveOptions,
CompareOptionspublic final Path compare(Path filePath)
Compares the specified file with the target documents and generates a comparison result.
filePath - Result document pathpublic final Path compare(Path filePath, CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
filePath - Result document file pathcompareOptions - The compare options to be used for the comparison processCompareOptionspublic final Path compare(Path filePath, SaveOptions saveOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
filePath - Result document file pathsaveOptions - Save optionsSaveOptionspublic final Path compare(Path filePath, SaveOptions saveOptions, CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
filePath - Result document file pathsaveOptions - The save options to be used for the saving the result documentcompareOptions - The compare options to be used for the comparison processSaveOptions,
CompareOptionspublic final Path compare(SaveOptions saveOptions, CompareOptions compareOptions)
Compares the specified file with the target documents without saving result.
saveOptions - Save optionscompareOptions - The compare options to be used for the comparison processCompareOptionspublic final Path compare(String filePath)
Compares the specified file with the target documents and generates a comparison result.
filePath - Result document pathpublic final Path compare(String filePath, CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
filePath - Result document file pathcompareOptions - The compare options to be used for the comparison processCompareOptionspublic final Path compare(String filePath, SaveOptions saveOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
filePath - Result document file pathsaveOptions - Save optionsSaveOptionspublic final Path compare(String filePath, SaveOptions saveOptions, CompareOptions compareOptions)
Compares the specified file with the target documents and writes a comparison result to the provided file path.
filePath - Result document file pathsaveOptions - The save options to be used for the saving the result documentcompareOptions - The compare options to be used for the comparison processSaveOptions,
CompareOptionspublic void compareDirectory(Path filePath, CompareOptions compareOptions)
filePath - The file path where the comparison result will be saved.compareOptions - The options to be used for the directory comparison process.public void compareDirectory(String filePath, CompareOptions compareOptions)
filePath - The file path where the comparison result will be saved.compareOptions - The options to be used for the directory comparison process.public final ChangeInfo[] getChanges()
Retrieves an array of ChangeInfo objects representing the changes detected during the comparison process.
Use this method to get detailed information about the changes between the source document and the target document(s).
Each ChangeInfo object contains information such as the type of change, the affected area,
and the content before and after the change.
ChangeInfo objects representing the changes detected during the comparison processChangeInfopublic final ChangeInfo[] getChanges(GetChangeOptions getChangeOptions)
Retrieves an array of ChangeInfo objects representing the changes detected during the comparison process.
Use this method to get detailed information about the changes between the source document and the target document(s).
Each ChangeInfo object contains information such as the type of change, the affected area,
and the content before and after the change.
Parameter GetChangeOptions allows to filter changes in different way.
getChangeOptions - The object that allows to filter changesChangeInfo objects representing the changes detected during the comparison processChangeInfopublic String getResultString()
Gets result string after comparison (For Text Comparison only).
public final Document getSource()
Gets the source document that is being compared.
Documentpublic String getSourceFolder()
Returns the source folder that is being compared.
public String getTargetFolder()
Returns the target folder that is being compared.
Copyright © 2024. All rights reserved.