public class PDFUtil extends Object
| Constructor and Description |
|---|
PDFUtil() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
compare(String file1,
String file2)
Compares two given pdf documents.
|
boolean |
compare(String file1,
String file2,
int startPage)
Compares two given pdf documents.
|
boolean |
compare(String file1,
String file2,
int startPage,
int endPage)
Compares two given pdf documents.
|
boolean |
compare(String file1,
String file2,
int startPage,
int endPage,
boolean highlightImageDifferences,
boolean showAllDifferences)
Compare 2 pdf documents pixel by pixel for the content and format.
|
void |
compareAllPages(boolean flag)
To compare all the pages of the PDF files.
|
void |
enableLog()
This method is used to show log in the console.
|
void |
excludeText(String... regexs) |
List<String> |
extractImages(String file)
Extract all the embedded images from the pdf document
|
List<String> |
extractImages(String file,
int startPage)
Extract all the embedded images from the pdf document
|
List<String> |
extractImages(String file,
int startPage,
int endPage)
Extract all the embedded images from the pdf document
|
CompareMode |
getCompareMode()
This method is used to get the current comparison mode text/visual
|
String |
getImageDestinationPath()
Path where images are stored
when the savePdfAsImage or extractPdfImages methods are invoked.
|
int |
getPageCount(String file)
Get the page count of the document.
|
String |
getText(String file)
Get the content of the document as plain text.
|
String |
getText(String file,
int startPage)
Get the content of the document as plain text.
|
String |
getText(String file,
int startPage,
int endPage)
Get the content of the document as plain text.
|
void |
highlightPdfDifference(boolean flag)
Highlight the difference when 2 pdf files are compared in Binary mode.
|
void |
highlightPdfDifference(Color colorCode)
Color in which pdf difference can be highlighted.
|
List<String> |
savePdfAsImage(String file)
Save each page of the pdf as image
|
List<String> |
savePdfAsImage(String file,
int startPage)
Save each page of the pdf as image
|
List<String> |
savePdfAsImage(String file,
int startPage,
int endPage)
Save each page of the pdf as image
|
void |
setCompareMode(CompareMode mode)
This method is used to change the file comparison mode text/visual
|
void |
setImageDestinationPath(String path)
Set the path where images to be stored
when the savePdfAsImage or extractPdfImages methods are invoked.
|
void |
setLogLevel(Level level)
This method is used to change the level
|
void |
trimWhiteSpace(boolean flag)
getText method by default replaces all the white spaces and compares.
|
void |
useStripper(org.apache.pdfbox.text.PDFTextStripper stripper)
To modify the text extracting strategy using PDFTextStripper
|
public void enableLog()
public void setCompareMode(CompareMode mode)
mode - CompareModepublic CompareMode getCompareMode()
public void setLogLevel(Level level)
level - java.util.logging.Levelpublic void trimWhiteSpace(boolean flag)
flag - true to enable; false otherwisepublic String getImageDestinationPath()
public void setImageDestinationPath(String path)
path - Absolute path to store the imagespublic void highlightPdfDifference(boolean flag)
flag - true - enable ; false - disable (default);public void highlightPdfDifference(Color colorCode)
colorCode - color code to highlight the differencepublic void compareAllPages(boolean flag)
flag - true to enable; false otherwisepublic void useStripper(org.apache.pdfbox.text.PDFTextStripper stripper)
stripper - Stripper with user strategypublic int getPageCount(String file) throws IOException
file - Absolute file pathIOException - when file is not found.public String getText(String file) throws IOException
file - Absolute file pathIOException - when file is not found.public String getText(String file, int startPage) throws IOException
file - Absolute file pathstartPage - Starting page number of the documentIOException - when file is not found.public String getText(String file, int startPage, int endPage) throws IOException
file - Absolute file pathstartPage - Starting page number of the documentendPage - Ending page number of the documentIOException - when file is not found.public void excludeText(String... regexs)
public boolean compare(String file1, String file2) throws IOException
file1 - Absolute file path of the expected filefile2 - Absolute file path of the actual fileIOException - when file is not found.public boolean compare(String file1, String file2, int startPage, int endPage) throws IOException
file1 - Absolute file path of the expected filefile2 - Absolute file path of the actual filestartPage - Starting page number of the documentendPage - Ending page number of the documentIOException - when file is not found.public boolean compare(String file1, String file2, int startPage) throws IOException
file1 - Absolute file path of the expected filefile2 - Absolute file path of the actual filestartPage - Starting page number of the documentIOException - when file is not found.public List<String> savePdfAsImage(String file, int startPage) throws IOException
file - Absolute file path of the filestartPage - Starting page number of the documentIOException - when file is not found.public List<String> savePdfAsImage(String file, int startPage, int endPage) throws IOException
file - Absolute file path of the filestartPage - Starting page number of the documentendPage - Ending page number of the documentIOException - when file is not found.public List<String> savePdfAsImage(String file) throws IOException
file - Absolute file path of the fileIOException - when file is not found.public boolean compare(String file1, String file2, int startPage, int endPage, boolean highlightImageDifferences, boolean showAllDifferences) throws IOException
file1 - Absolute file path of the expected filefile2 - Absolute file path of the actual filestartPage - Starting page number of the documentendPage - Ending page number of the documenthighlightImageDifferences - To highlight differences in the imagesshowAllDifferences - To compare all the pages of the PDF (by default as soon as a mismatch is found in a page, this method exits)IOException - when file is not found.public List<String> extractImages(String file, int startPage) throws IOException
file - Absolute file path of the filestartPage - Starting page number of the documentIOException - when file is not found.public List<String> extractImages(String file, int startPage, int endPage) throws IOException
file - Absolute file path of the filestartPage - Starting page number of the documentendPage - Ending page number of the documentIOException - when file is not found.public List<String> extractImages(String file) throws IOException
file - Absolute file path of the fileIOException - when file is not found.Copyright © 2017. All rights reserved.