PDF documents can be compared as rendered images (PNG) to ensure that a test document and a master document have the same layout.
<testcase name="haveSameAppearance_CompleteDocument"> <assertThat testDocument="test/test.pdf" masterDocument="master/master.pdf" > <haveSameAppearance on="EVERY_PAGE" /> </assertThat> </testcase>
You can select individual pages in many ways. All possibilities are described in chapter 13.2: “Page Selection”.
<testcase name="haveSameAppearance_OnFirstPage_InClippingArea"> <assertThat testDocument="test/test.pdf" masterDocument="master/master.pdf" > <haveSameAppearance on="FIRST_PAGE"> <inClippingArea upperLeftX="50" upperLeftY="755" width="370" height="35" unit="POINTS" /> </haveSameAppearance> </assertThat> </testcase>
A clipping area can be defined using the measuring units
DPI72. All constants are declared with XML Schema for
If you omit a measuring unit, the values are taken as
The diff image contains the name of the test in the header. And the name of the diff image is shown in the error message. That allows a cross reference between test and diff image.
The filename of a diff-image file is built as follows:
The first part is the full name of the test file.
If the tested file is a stream, the name starts with “_pdfunit_stream_”. If it is a byte array, it starts with “_pdfunit_bytearray_”. Both strings are extended by a random number.
The second part is a formatted date in the format “yyyyMMdd-HHmmssSSS”.
The last part of the file name is the string “.out.png”.
Due to the default configuration a diff image for test files is stored in the same directory in which the test file is located. Diff images for streams and byte arrays are stored in the home directory of the current Java process. You can change these settings in the config.properties file.
If you need to analyze the layout of two PDF documents after a test fails, you
can use the very powerful program
DiffPDF. Information about this Open-Source
application by Mark Summerfield is available on the project site
You can install the program under Linux with a package manager, for example
apt-get install diffpdf. On Windows you can use it as a “portable application”