public class CompareTool extends Object
Modifier and Type | Class and Description |
---|---|
class |
CompareTool.CompareResult
Class containing results of the comparison of two documents.
|
class |
CompareTool.CompareToolExecutionException |
class |
CompareTool.ObjectPath
Class that helps to find two corresponding objects in the comparing documents and also keeps track of the already met in comparing process parent indirect objects.
|
Constructor and Description |
---|
CompareTool()
Creates an instance of the CompareTool.
|
Modifier and Type | Method and Description |
---|---|
boolean |
compareArrays(PdfArray outArray, PdfArray cmpArray)
Simple method that compares two given PdfArrays by content.
|
boolean |
compareBooleans(PdfBoolean outBoolean, PdfBoolean cmpBoolean)
Simple method that compares two given PdfBooleans.
|
CompareTool.CompareResult |
compareByCatalog(PdfDocument outDocument, PdfDocument cmpDocument)
Compares two PDF documents by content starting from Catalog dictionary and then recursively comparing corresponding objects which are referenced from it.
|
String |
compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix)
Compares two PDF documents by content starting from page dictionaries and then recursively comparing corresponding objects which are referenced from them.
|
String |
compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, byte[] outPass, byte[] cmpPass)
This method overload is used to compare two encrypted PDF documents.
|
String |
compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer,List<Rectangle>> ignoredAreas)
Compares two PDF documents by content starting from page dictionaries and then recursively comparing corresponding objects which are referenced from them.
|
String |
compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer,List<Rectangle>> ignoredAreas, byte[] outPass, byte[] cmpPass)
This method overload is used to compare two encrypted PDF documents.
|
boolean |
compareDictionaries(PdfDictionary outDict, PdfDictionary cmpDict)
Simple method that compares two given PdfDictionaries by content.
|
String |
compareDocumentInfo(String outPdf, String cmpPdf)
Compares document info dictionaries of two pdf documents.
|
String |
compareDocumentInfo(String outPdf, String cmpPdf, byte[] outPass, byte[] cmpPass)
This method overload is used to compare two encrypted PDF documents.
|
String |
compareLinkAnnotations(String outPdf, String cmpPdf)
Compares if two documents has identical link annotations on corresponding pages.
|
boolean |
compareNames(PdfName outName, PdfName cmpName)
Simple method that compares two given PdfNames.
|
boolean |
compareNumbers(PdfNumber outNumber, PdfNumber cmpNumber)
Simple method that compares two given PdfNumbers.
|
boolean |
compareStreams(PdfStream outStream, PdfStream cmpStream)
Simple method that compares two given PdfStreams by content.
|
boolean |
compareStrings(PdfString outString, PdfString cmpString)
Simple method that compares two given PdfStrings.
|
String |
compareTagStructures(String outPdf, String cmpPdf)
Compares tag structures of the two PDF documents.
|
String |
compareVisually(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix)
Compares two documents visually.
|
String |
compareVisually(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer,List<Rectangle>> ignoredAreas)
Compares two documents visually.
|
boolean |
compareXmls(byte[] xml1, byte[] xml2)
Utility method that provides simple comparison of the two xml files stored in byte arrays.
|
boolean |
compareXmls(String xmlFilePath1, String xmlFilePath2)
Utility method that provides simple comparison of the two xml files.
|
String |
compareXmp(String outPdf, String cmpPdf)
Compares xmp metadata of the two given PDF documents.
|
String |
compareXmp(String outPdf, String cmpPdf, boolean ignoreDateAndProducerProperties)
Compares xmp metadata of the two given PDF documents.
|
CompareTool |
disableCachedPagesComparison()
Disables the default logic of pages comparison.
|
CompareTool |
enableEncryptionCompare()
Enables the comparison of the encryption properties of the documents.
|
ReaderProperties |
getCmpReaderProperties()
Documents for comparison are opened in reader mode.
|
ReaderProperties |
getOutReaderProperties()
Documents for comparison are opened in reader mode.
|
CompareTool |
setCompareByContentErrorsLimit(int compareByContentMaxErrorCount)
Sets the maximum errors count which will be returned as the result of the comparison.
|
CompareTool |
setGenerateCompareByContentXmlReport(boolean generateCompareByContentXmlReport)
Enables or disables the generation of the comparison report in the form of the xml document.
|
public CompareTool.CompareResult compareByCatalog(PdfDocument outDocument, PdfDocument cmpDocument) throws IOException
compareByContent(String, String, String, String)
methods is the return value. This method returns a CompareTool.CompareResult
class instance, which could be used in code, however compareByContent methods in case of the differences simply return String value, which could only be printed. Also, keep in mind that this method doesn't perform visual comparison of the documents.
CompareTool
class description.
outDocument
- the absolute path to the output file, which is to be compared to cmp-file.
cmpDocument
- the absolute path to the cmp-file, which is to be compared to output file.
CompareTool.CompareResult
for more info.
IOException
public CompareTool disableCachedPagesComparison()
compareByCatalog(PdfDocument, PdfDocument)
method.
By default, pages are treated as special objects and if they are met in the process of comparison, then they are not checked as objects, but rather simply checked that they has same page numbers in both documents. This behaviour is intended for the compareByContent(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
set of methods, because in them documents are compared in page by page basis. Thus, we don't need to check if pages are of the same content when they are met in comparison process, we are sure that we will compare their content or we have already compared them.
However, if you would use compareByCatalog(com.itextpdf.kernel.pdf.PdfDocument, com.itextpdf.kernel.pdf.PdfDocument)
with default behaviour of pages comparison, pages won't be checked at all, every time when reference to the page dictionary is met, only page numbers will be compared for both documents. You can say that in this case, comparison will be performed for all document's catalog entries except /Pages (However in fact, document's page tree structures will be compared, but pages themselves - won't).
CompareTool
instance.
public CompareTool setCompareByContentErrorsLimit(int compareByContentMaxErrorCount)
compareByContentMaxErrorCount
- the errors count.
public CompareTool setGenerateCompareByContentXmlReport(boolean generateCompareByContentXmlReport)
generateCompareByContentXmlReport
- true to enable xml report generation, false - to disable.
public CompareTool enableEncryptionCompare()
public ReaderProperties getOutReaderProperties()
ReaderProperties
which are used to open output document. This is particularly useful for comparison of encrypted documents.
For more explanations about what is outDoc and cmpDoc see last paragraph of the CompareTool
class description.
ReaderProperties
instance which will be later passed to the output document PdfReader
.
public ReaderProperties getCmpReaderProperties()
ReaderProperties
which are used to open cmp document. This is particularly useful for comparison of encrypted documents.
For more explanations about what is outDoc and cmpDoc see last paragraph of the CompareTool
class description.
ReaderProperties
instance which will be later passed to the cmp document PdfReader
.
public String compareVisually(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix) throws InterruptedException, IOException
CompareTool
class description.
outPdf
- the absolute path to the output file, which is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which is to be compared to output file.
outPath
- the absolute path to the folder, which will be used to store image files for visual comparison.
differenceImagePrefix
- file name prefix for image files with marked differences if there is any.
InterruptedException
IOException
public String compareVisually(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer,List<Rectangle>> ignoredAreas) throws InterruptedException, IOException
CompareTool
class description.
outPdf
- the absolute path to the output file, which is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which is to be compared to output file.
outPath
- the absolute path to the folder, which will be used to store image files for visual comparison.
differenceImagePrefix
- file name prefix for image files with marked differences if there is any.
ignoredAreas
- a map with one-based page numbers as keys and lists of ignored rectangles as values.
InterruptedException
IOException
public String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix) throws InterruptedException, IOException
compareByCatalog(PdfDocument, PdfDocument)
this method performs content comparison page by page and doesn't compare the tag structure, acroforms and all other things that doesn't belong to specific pages.
compareVisually(String, String, String, String)
.
CompareTool
class description.
outPdf
- the absolute path to the output file, which is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which is to be compared to output file.
outPath
- the absolute path to the folder, which will be used to store image files for visual comparison.
differenceImagePrefix
- file name prefix for image files with marked visual differences if there is any.
InterruptedException
IOException
public String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, byte[] outPass, byte[] cmpPass) throws InterruptedException, IOException
compareByCatalog(PdfDocument, PdfDocument)
this method performs content comparison page by page and doesn't compare the tag structure, acroforms and all other things that doesn't belong to specific pages.
compareVisually(String, String, String, String)
.
CompareTool
class description.
outPdf
- the absolute path to the output file, which is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which is to be compared to output file.
outPath
- the absolute path to the folder, which will be used to store image files for visual comparison.
differenceImagePrefix
- file name prefix for image files with marked visual differences if there is any.
outPass
- password for the encrypted document specified by the outPdf absolute path.
cmpPass
- password for the encrypted document specified by the cmpPdf absolute path.
InterruptedException
IOException
public String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer,List<Rectangle>> ignoredAreas) throws InterruptedException, IOException
compareByCatalog(PdfDocument, PdfDocument)
this method performs content comparison page by page and doesn't compare the tag structure, acroforms and all other things that doesn't belong to specific pages.
compareVisually(String, String, String, String, Map)
.
CompareTool
class description.
outPdf
- the absolute path to the output file, which is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which is to be compared to output file.
outPath
- the absolute path to the folder, which will be used to store image files for visual comparison.
differenceImagePrefix
- file name prefix for image files with marked visual differences if there is any.
ignoredAreas
- a map with one-based page numbers as keys and lists of ignored rectangles as values.
InterruptedException
IOException
public String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer,List<Rectangle>> ignoredAreas, byte[] outPass, byte[] cmpPass) throws InterruptedException, IOException
compareByCatalog(PdfDocument, PdfDocument)
this method performs content comparison page by page and doesn't compare the tag structure, acroforms and all other things that doesn't belong to specific pages.
compareVisually(String, String, String, String, Map)
.
CompareTool
class description.
outPdf
- the absolute path to the output file, which is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which is to be compared to output file.
outPath
- the absolute path to the folder, which will be used to store image files for visual comparison.
differenceImagePrefix
- file name prefix for image files with marked visual differences if there is any.
ignoredAreas
- a map with one-based page numbers as keys and lists of ignored rectangles as values.
outPass
- password for the encrypted document specified by the outPdf absolute path.
cmpPass
- password for the encrypted document specified by the cmpPdf absolute path.
InterruptedException
IOException
public boolean compareDictionaries(PdfDictionary outDict, PdfDictionary cmpDict) throws IOException
outDict
- dictionary to compare.
cmpDict
- dictionary to compare.
IOException
public boolean compareStreams(PdfStream outStream, PdfStream cmpStream) throws IOException
outStream
- stream to compare.
cmpStream
- stream to compare.
IOException
public boolean compareArrays(PdfArray outArray, PdfArray cmpArray) throws IOException
outArray
- array to compare.
cmpArray
- array to compare.
IOException
public boolean compareNames(PdfName outName, PdfName cmpName)
outName
- name to compare.
cmpName
- name to compare.
public boolean compareNumbers(PdfNumber outNumber, PdfNumber cmpNumber)
outNumber
- number to compare.
cmpNumber
- number to compare.
public boolean compareStrings(PdfString outString, PdfString cmpString)
outString
- string to compare.
cmpString
- string to compare.
public boolean compareBooleans(PdfBoolean outBoolean, PdfBoolean cmpBoolean)
outBoolean
- boolean to compare.
cmpBoolean
- boolean to compare.
public String compareXmp(String outPdf, String cmpPdf)
outPdf
- the absolute path to the output file, which xmp is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which xmp is to be compared to output file.
public String compareXmp(String outPdf, String cmpPdf, boolean ignoreDateAndProducerProperties)
outPdf
- the absolute path to the output file, which xmp is to be compared to cmp-file.
cmpPdf
- the absolute path to the cmp-file, which xmp is to be compared to output file.
ignoreDateAndProducerProperties
- true, if to ignore differences in date or producer xmp metadata properties.
public boolean compareXmls(byte[] xml1, byte[] xml2) throws ParserConfigurationException, SAXException, IOException
xml1
- first xml file data to compare.
xml2
- second xml file data to compare.
ParserConfigurationException
SAXException
IOException
public boolean compareXmls(String xmlFilePath1, String xmlFilePath2) throws ParserConfigurationException, SAXException, IOException
xmlFilePath1
- absolute path to the first xml file to compare.
xmlFilePath2
- absolute path to the second xml file to compare.
ParserConfigurationException
SAXException
IOException
public String compareDocumentInfo(String outPdf, String cmpPdf, byte[] outPass, byte[] cmpPass) throws IOException
outPdf
- the absolute path to the output file, which info is to be compared to cmp-file info.
cmpPdf
- the absolute path to the cmp-file, which info is to be compared to output file info.
outPass
- password for the encrypted document specified by the outPdf absolute path.
cmpPass
- password for the encrypted document specified by the cmpPdf absolute path.
IOException
public String compareDocumentInfo(String outPdf, String cmpPdf) throws IOException
outPdf
- the absolute path to the output file, which info is to be compared to cmp-file info.
cmpPdf
- the absolute path to the cmp-file, which info is to be compared to output file info.
IOException
public String compareLinkAnnotations(String outPdf, String cmpPdf) throws IOException
outPdf
- the absolute path to the output file, which links are to be compared to cmp-file links.
cmpPdf
- the absolute path to the cmp-file, which links are to be compared to output file links.
IOException
public String compareTagStructures(String outPdf, String cmpPdf) throws IOException, ParserConfigurationException, SAXException
outPdf
- the absolute path to the output file, which tags are to be compared to cmp-file tags.
cmpPdf
- the absolute path to the cmp-file, which tags are to be compared to output file tags.
IOException
ParserConfigurationException
SAXException
Copyright © 1998–2018 iText Group NV. All rights reserved.