4.17.  Comparing Text

PDFUnit can compare text on any page of a test document with the corresponding page of a master document. The following simple example shows how to do this (please note that whitespaces are ignored):

<testcase name="haveSameText_CompleteDocument">
  <assertThat testDocument="test/test.pdf"
              masterDocument="master/master.pdf"
  >
    <haveSameText on="EVERY_PAGE" />
  </assertThat>
</testcase>

You can restrict the test to selected pages which is explained in chapter 13.2: “Page Selection”:

<testcase name="haveSameText_OnSinglePage">
  <assertThat testDocument="test/test.pdf"
              masterDocument="master/master.pdf"
  >
    <haveSameText on="FIRST_PAGE" />
  </assertThat>
</testcase>
<testcase name="compareText_OnLastPage">
  <assertThat testDocument="test/test.pdf"
              masterDocument="master/master.pdf"
  >
    <haveSameText on="LAST_PAGE" />
  </assertThat>
</testcase>

And you can restrict the comparison to a section of a page:

<testcase name="haveSameText_CompleteDocument_InClippingArea">
  <assertThat testDocument="test/test.pdf"
              masterDocument="master/master.pdf"
  >
    <haveSameText on="EVERY_PAGE" >
      <inClippingArea upperLeftX="50" upperLeftY="755" 
                      width="370" height="35" 
                      unit="POINTS"
      />
    </haveSameText>
  </assertThat>
</testcase>