Package de.redsix.pdfcompare
Class PdfComparator<T extends CompareResultImpl>
java.lang.Object
de.redsix.pdfcompare.PdfComparator<T>
- Type Parameters:
T- Allows to specify different CompareResults.
The PdfComparator is the entry point to use for comparing documents.
It allows to specify which documents to compare and which additional features to apply, like
ignores and passwords.
One PdfCompare object is created for every comparison and they are not reused.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPdfComparator(File expectedFile, File actualFile) Compare two PDFs by providing two File objects for the expected PDF and the actual PDF.PdfComparator(File expectedFile, File actualFile, T compareResult) Compare two PDFs by providing two File objects for the expected PDF and the actual PDF.PdfComparator(InputStream expectedPdfIS, InputStream actualPdfIS) Compare two PDFs by providing two InputStream objects for the expected PDF and the actual PDF.PdfComparator(InputStream expectedPdfIS, InputStream actualPdfIS, T compareResult) Compare two PDFs by providing two InputStream objects for the expected PDF and the actual PDF.PdfComparator(String expectedPdfFilename, String actualPdfFilename) Compare two PDFs by providing two filenames for the expected PDF and the actual PDF.PdfComparator(String expectedPdfFilename, String actualPdfFilename, T compareResult) Compare two PDFs by providing two filenames for the expected PDF and the actual PDF.PdfComparator(Path expectedPath, Path actualPath) Compare two PDFs by providing two Path objects for the expected PDF and the actual PDF.PdfComparator(Path expectedPath, Path actualPath, T compareResult) Compare two PDFs by providing two Path objects for the expected PDF and the actual PDF. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends CompareResultImpl>
PdfComparatorCompare two PDFs, that are given as base64 encoded strings.static <T extends CompareResultImpl>
PdfComparatorCompare two PDFs, that are given as base64 encoded strings.compare()Does the actual comparison of the given PDF documents.static ImageWithDimensionrenderPageAsImage(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.rendering.PDFRenderer expectedPdfRenderer, int pageIndex, Environment environment) voidsetEnvironment(Environment environment) Deprecated.Deprecated.UsewithIgnore(PageArea)instead.withActualPassword(String password) withEnvironment(Environment environment) Allows to inject an Environment that can override environment settings.withExpectedPassword(String password) withIgnore(PageArea exclusion) Allows to specify an area of a page that is excluded during the comparison.withIgnore(File ignoreFile) Reads a file with Exclusions.withIgnore(InputStream ignoreIS) Reads Exclusions from an InputStream.withIgnore(String ignoreFilename) Reads a file with Exclusions.withIgnore(Path ignorePath) Reads a file with Exclusions.
-
Field Details
-
MARKER_WIDTH
public static final int MARKER_WIDTH- See Also:
-
-
Constructor Details
-
PdfComparator
Compare two PDFs by providing two filenames for the expected PDF and the actual PDF.- Parameters:
expectedPdfFilename- filename for the expected PDFactualPdfFilename- filename for the actual PDF
-
PdfComparator
Compare two PDFs by providing two filenames for the expected PDF and the actual PDF.- Parameters:
expectedPdfFilename- filename for the expected PDFactualPdfFilename- filename for the actual PDFcompareResult- the CompareResult to use during this compare. Allows to provide CompareResultImpl Subtypes with Swapping for example.
-
PdfComparator
Compare two PDFs by providing two Path objects for the expected PDF and the actual PDF.- Parameters:
expectedPath- Path for the expected PDFactualPath- Path for the actual PDF
-
PdfComparator
Compare two PDFs by providing two Path objects for the expected PDF and the actual PDF.- Parameters:
expectedPath- Path for the expected PDFactualPath- Path for the actual PDFcompareResult- the CompareResult to use during this compare. Allows to provide CompareResultImpl Subtypes with Swapping for example.
-
PdfComparator
Compare two PDFs by providing two File objects for the expected PDF and the actual PDF.- Parameters:
expectedFile- File for the expected PDFactualFile- File for the actual PDF
-
PdfComparator
Compare two PDFs by providing two File objects for the expected PDF and the actual PDF.- Parameters:
expectedFile- File for the expected PDFactualFile- File for the actual PDFcompareResult- the CompareResult to use during this compare. Allows to provide CompareResultImpl Subtypes with Swapping for example.
-
PdfComparator
Compare two PDFs by providing two InputStream objects for the expected PDF and the actual PDF.- Parameters:
expectedPdfIS- InputStream for the expected PDFactualPdfIS- InputStream for the actual PDF
-
PdfComparator
Compare two PDFs by providing two InputStream objects for the expected PDF and the actual PDF.- Parameters:
expectedPdfIS- InputStream for the expected PDFactualPdfIS- InputStream for the actual PDFcompareResult- the CompareResult to use during this compare. Allows to provide CompareResultImpl Subtypes with Swapping for example.
-
-
Method Details
-
base64
public static <T extends CompareResultImpl> PdfComparator base64(String expectedPdfBase64, String actualPdfBase64) Compare two PDFs, that are given as base64 encoded strings.- Parameters:
expectedPdfBase64- expected PDF in base64 encoded formatactualPdfBase64- actual PDF in base64 encoded format- Returns:
- A CompareResultImpl object, that contains the result of this compare.
-
base64
public static <T extends CompareResultImpl> PdfComparator base64(String expectedPdfBase64, String actualPdfBase64, T compareResult) Compare two PDFs, that are given as base64 encoded strings.- Parameters:
expectedPdfBase64- expected PDF in base64 encoded formatactualPdfBase64- actual PDF in base64 encoded formatcompareResult- the CompareResult to use during this compare. Allows to provide CompareResultImpl Subtypes with Swapping for example.- Returns:
- A CompareResultImpl object, that contains the result of this compare.
-
setEnvironment
Deprecated.usewithEnvironment(Environment)instead. -
withEnvironment
Allows to inject an Environment that can override environment settings.SimpleEnvironmentis particularly useful if you want to override some properties. If you want to specify your own config file, instead of the default application.conf in the root of the classpath, you an use aConfigFileEnvironment.- Parameters:
environment- the environment so use- Returns:
- this
- Throws:
IllegalStateException- when withIgnore methods are called before this method.
-
withIgnore
Reads a file with Exclusions.- Parameters:
ignoreFilename- The file to read- Returns:
- this
- See Also:
-
withIgnore
Reads a file with Exclusions.- Parameters:
ignoreFile- The file to read- Returns:
- this
- See Also:
-
withIgnore
Reads a file with Exclusions.It is possible to define rectangular areas that are ignored during comparison. For that, a file needs to be created, which defines areas to ignore. The file format is JSON (or actually a superset called HOCON) and has the following form:
exclusions: [ { page: 2 x1: 300 // entries without a unit are in pixels, when Pdf is rendered at 300DPI y1: 1000 x2: 550 y2: 1300 }, { // page is optional. When not given, the exclusion applies to all pages. x1: 130.5mm // entries can also be given in units of cm, mm or pt (DTP-Point defined as 1/72 Inches) y1: 3.3cm x2: 190mm y2: 3.7cm }, { page: 7 // coordinates are optional. When not given, the whole page is excluded. } ]- Parameters:
ignorePath- The file to read- Returns:
- this
-
withIgnore
Reads Exclusions from an InputStream.- Parameters:
ignoreIS- The file to read- Returns:
- this
- See Also:
-
withIgnore
Allows to specify an area of a page that is excluded during the comparison.- Parameters:
exclusion- An area of the document, that shall be ignored.- Returns:
- this
-
with
Deprecated.UsewithIgnore(PageArea)instead.Allows to specify an area of a page that is excluded during the comparison.- Parameters:
exclusion- An area of the document, that shall be ignored.- Returns:
- this
-
withExpectedPassword
-
withActualPassword
-
compare
Does the actual comparison of the given PDF documents. When errors occur during the rendering or diffing of pages, they are collected and added to a RenderingException as SuppressedExceptions.- Returns:
- the CompareResult gives information about the comparison
- Throws:
IOException- when an input file or stream can not be readRenderingException- when errors during rendering or diffing of pages occurred
-
renderPageAsImage
public static ImageWithDimension renderPageAsImage(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.rendering.PDFRenderer expectedPdfRenderer, int pageIndex, Environment environment) throws IOException - Throws:
IOException
-
getResult
-
withEnvironment(Environment)instead.