3.17.  Layout - Entire PDF Pages


Text in a PDF document has properties such as font size, font color and lines which should be correct before sending it to the customer. Also paragraphs, alignment of text, images and image descriptions are important parts of the layout. PDFUnit tests these aspects, first rendering the document page by page and then comparing each page:

Tests with rendered PDF pages can be carried out with the tag <asRenderedPage />:

<!-- Tags to compare rendered PDF pages with image files: -->

<asRenderedPage on=".."                 (One of these attributes ...
                onPage=".."             ...
                onEveryPageAfter=".."   ...
                onEveryPageBefore=".."  ...
                onAnyPageAfter=".."     ...
                onAnyPageBefore=".."    ... is required)

<!-- Nested tag of <asRenderedPage> : -->

<isEqualTo  image=".."               (required)
            positionUpperLeftX=".."  (optional)
            positionUpperLeftY=".."  (optional)
            unit=".."                (optional)

You can specify individual pages to be compared. This is described in the chapter 13.2: “Page Selection”.

The current chapter deals only with the comparison of full pages. If it does not make sense to compare a complete rendered PDF page with an image, the comparison can be limited to a section of a page. The following chapter 3.18: “Layout - in Clipping Areas” describes that topic.

Example - Compare Preselected Pages as Rendered Images

The following example checks that the pages 1, 3 and 4 look the same as referenced image files:

<testcase name="compareAsRenderedPage_MultipleImages">
  <assertThat testDocument="master/documentUnderTest.pdf">
    <asRenderedPage onPage="1, 3, 4">
      <isEqualTo image="master/documentUnderTest_Page1.png" />
      <isEqualTo image="master/documentUnderTest_Page3.png" />
      <isEqualTo image="master/documentUnderTest_Page4.png" />

Image Format of Rendered Pages

Supported image types are GIF, PNG, JPEG, BMP and WBMP.