Top Inners Fields Constructors Methods
com.openhtmltopdf.pdfboxout.visualtester

public Class PdfVisualTester

extends Object
Class Inheritance
Imports
java.awt.Color, .Font, .Graphics2D, .RenderingHints, java.awt.image.BufferedImage, .DataBuffer, .DataBufferByte, .DataBufferDouble, .DataBufferFloat, .DataBufferInt, .DataBufferShort, .DataBufferUShort, java.io.IOException, java.util.ArrayList, .Arrays, .List, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.rendering.ImageType, .PDFRenderer

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static enum
public static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final BufferedImage

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static int
calcCombinedIntensity(final int element)

Calculate the combined intensity of a pixel and normalizes it to a value of at most 255.

private static int
color(final int r, final int g, final int b)

public static List<PdfVisualTester.PdfCompareResult>

Returns:

A list of PdfCompareResult instances describing differences.
comparePdfDocuments
(byte[] expected, byte[] actual, String testName, boolean
Whether to return the images in the case they are good (ie. the same).
keepSameImages
)

Compares two PDF documents by rendering each page to an image and comparing pixel by pixel.

public static BufferedImage
private static int
fade(final int i)

private static int
fadeElement(final int i)

private static int
getActualPixel(BufferedImage img, int x, int y)

private static int
getElement(final int expectedElement, final int actualElement)

private static int
getExpectedPixel(BufferedImage img, int x, int y)

private static boolean

Returns:

whether imgExpected is different image compared to imgActual
isImageDifferent
(BufferedImage imgExpected, BufferedImage imgActual)

Gets the data buffer of each image and compares.

private static int

Returns:

A value that is at least 50 and at most maxIntensity
levelIntensity
(final int
color component to level
darkness
,
final int
highest possible intensity cut off
maxIntensity
)

Levels the color intensity to at least 50 and at most maxIntensity.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LEFT_MARGIN_PXback to summary
private static final int LEFT_MARGIN_PX
LINE_HEIGHT_PXback to summary
private static final int LINE_HEIGHT_PX
ONE_PX_IMAGEback to summary
private static final BufferedImage ONE_PX_IMAGE

Constructor Detail

PdfVisualTesterback to summary
public PdfVisualTester()

Method Detail

calcCombinedIntensityback to summary
private static int calcCombinedIntensity(final int element)

Calculate the combined intensity of a pixel and normalizes it to a value of at most 255.

colorback to summary
private static int color(final int r, final int g, final int b)
comparePdfDocumentsback to summary
public static List<PdfVisualTester.PdfCompareResult> comparePdfDocuments(byte[] expected, byte[] actual, String testName, boolean keepSameImages) throws IOException

Compares two PDF documents by rendering each page to an image and comparing pixel by pixel.

Parameters
keepSameImages:boolean

Whether to return the images in the case they are good (ie. the same).

Returns:List<PdfVisualTester.PdfCompareResult>

A list of PdfCompareResult instances describing differences.

createDiffImageback to summary
public static BufferedImage createDiffImage(BufferedImage img1, BufferedImage img2)
fadeback to summary
private static int fade(final int i)
fadeElementback to summary
private static int fadeElement(final int i)
getActualPixelback to summary
private static int getActualPixel(BufferedImage img, int x, int y)
getElementback to summary
private static int getElement(final int expectedElement, final int actualElement)
getExpectedPixelback to summary
private static int getExpectedPixel(BufferedImage img, int x, int y)
isImageDifferentback to summary
private static boolean isImageDifferent(BufferedImage imgExpected, BufferedImage imgActual)

Gets the data buffer of each image and compares.

Note

May be an expensive (memory and CPU) operation for large images.

Returns:boolean

whether imgExpected is different image compared to imgActual

levelIntensityback to summary
private static int levelIntensity(final int darkness, final int maxIntensity)

Levels the color intensity to at least 50 and at most maxIntensity.

Parameters
darkness:int

color component to level

maxIntensity:int

highest possible intensity cut off

Returns:int

A value that is at least 50 and at most maxIntensity

com.openhtmltopdf.pdfboxout.visualtester back to summary

public Class PdfVisualTester.PdfCompareResult

extends Object
Class Inheritance
  • java.lang.Object
  • com.openhtmltopdf.pdfboxout.visualtester.PdfVisualTester.PdfCompareResult

Field Summary

Modifier and TypeField and Description
public static final int
public final String
public final int
public final PdfVisualTester.TestImage
public final PdfVisualTester.ProblemType

Constructor Summary

AccessConstructor and Description
private
PdfCompareResult(PdfVisualTester.ProblemType type, String logMessage, int pageNumber, PdfVisualTester.TestImage testImage)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INALID_PAGE_NOback to summary
public static final int INALID_PAGE_NO
logMessageback to summary
public final String logMessage
pageNumberback to summary
public final int pageNumber
testImagesback to summary
public final PdfVisualTester.TestImage testImages
typeback to summary
public final PdfVisualTester.ProblemType type

Constructor Detail

PdfCompareResultback to summary
private PdfCompareResult(PdfVisualTester.ProblemType type, String logMessage, int pageNumber, PdfVisualTester.TestImage testImage)
com.openhtmltopdf.pdfboxout.visualtester back to summary

public final Enum PdfVisualTester.ProblemType

extends Enum<PdfVisualTester.ProblemType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final PdfVisualTester.ProblemType
public static final PdfVisualTester.ProblemType
public static final PdfVisualTester.ProblemType
public static final PdfVisualTester.ProblemType
public static final PdfVisualTester.ProblemType
public static final PdfVisualTester.ProblemType
public static final PdfVisualTester.ProblemType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PdfVisualTester.ProblemType
public static PdfVisualTester.ProblemType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EXTRA_EXPECTED_PAGEback to summary
public static final PdfVisualTester.ProblemType EXTRA_EXPECTED_PAGE
NO_ACTUAL_DOCUMENT_PROVIDEDback to summary
public static final PdfVisualTester.ProblemType NO_ACTUAL_DOCUMENT_PROVIDED
NO_EXPECTED_DOCUMENT_PROVIDEDback to summary
public static final PdfVisualTester.ProblemType NO_EXPECTED_DOCUMENT_PROVIDED
PAGE_COUNT_DIFFERENTback to summary
public static final PdfVisualTester.ProblemType PAGE_COUNT_DIFFERENT
PAGE_GOODback to summary
public static final PdfVisualTester.ProblemType PAGE_GOOD
PAGE_SIZE_DIFFERENTback to summary
public static final PdfVisualTester.ProblemType PAGE_SIZE_DIFFERENT
PAGE_VISUALLY_DIFFERENTback to summary
public static final PdfVisualTester.ProblemType PAGE_VISUALLY_DIFFERENT

Constructor Detail

ProblemTypeback to summary
private ProblemType()

Method Detail

valueOfback to summary
public static PdfVisualTester.ProblemType valueOf(String name)
valuesback to summary
public static PdfVisualTester.ProblemType[] values()
com.openhtmltopdf.pdfboxout.visualtester back to summary

public Class PdfVisualTester.TestImage

extends Object
Class Inheritance
  • java.lang.Object
  • com.openhtmltopdf.pdfboxout.visualtester.PdfVisualTester.TestImage

Field Summary

Modifier and TypeField and Description
private final BufferedImage
private final boolean
private final BufferedImage
private final int
private final String

Constructor Summary

AccessConstructor and Description
private
TestImage(String test, int pageNo, BufferedImage exp, BufferedImage act, boolean hasDifferences)

Method Summary

Modifier and TypeMethod and Description
public BufferedImage

Returns:

the diff image.
createDiff
()

Creates a diff image to quickly spot differences between expected and actual.

public BufferedImage

Returns:

the actual image, may be null if expected has more pages than actual
getActual
()

Get the actual rendered image.

public BufferedImage

Returns:

the expected image, should never be null.
getExpected
()

Get the expected rendered image.

public int

Returns:

the page number.
getPageNumber
()

public String
public boolean

Returns:

true if the images are different. Precaulculated.
hasDifferences
()

Should usually be called before createDiff().

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualback to summary
private final BufferedImage actual
differencesback to summary
private final boolean differences
expectedback to summary
private final BufferedImage expected
pageNumberback to summary
private final int pageNumber
testNameback to summary
private final String testName

Constructor Detail

TestImageback to summary
private TestImage(String test, int pageNo, BufferedImage exp, BufferedImage act, boolean hasDifferences)

Method Detail

createDiffback to summary
public BufferedImage createDiff()

Creates a diff image to quickly spot differences between expected and actual.

Note

May be expensive for large images.

Returns:BufferedImage

the diff image.

See Also
hasDifferences
getActualback to summary
public BufferedImage getActual()

Get the actual rendered image.

Returns:BufferedImage

the actual image, may be null if expected has more pages than actual

getExpectedback to summary
public BufferedImage getExpected()

Get the expected rendered image.

Returns:BufferedImage

the expected image, should never be null.

getPageNumberback to summary
public int getPageNumber()
Returns:int

the page number.

getTestNameback to summary
public String getTestName()
Returns:String

the test name passed into PdfVisualTester#comparePdfDocuments(byte[], byte[], String, boolean)

hasDifferencesback to summary
public boolean hasDifferences()

Should usually be called before createDiff().

Returns:boolean

true if the images are different. Precaulculated.