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:
... with an existing image file. PDFUnit's utility program RenderPdfToImages
creates
images of one or more PDF pages. Chapter
9.14: “Render Pages to PNG”
explains how to use it.
... with a rendered page of a master document. The chapter 4.12: “Comparing Layout as Rendered Pages” describes tests with master documents.
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.
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" /> </asRenderedPage> </assertThat> </testcase>