3.12.  Format


You need to check that the intended format was created successfully: A4-landscape, Letter-portrait or a special format for a poster? You think testing such simple thing is a waste of time? But have you ever printed a LETTER-formatted document on an A4-printer? It is possible ... ;-(

That is the reason why PDFUnit provides the tag <hasFormat /> to verify the format:

<!-- Tag to check the format: -->

<hasFormat format=".."            (either 'format' or 
           width=".."             'width' and 'height' has to be used)
           unit=".."              (optional)
           on=".."                (one of the page selection attributes
           onPage".."             ...
           onEveryPageAfter".."   ...
           onEveryPageBefore".."  ...
           onAnyPageAfter".."     ...
           onAnyPageBefore".."    ... can be used)

Documents with one Page Format

A page format can be checked with predefined constants:

<testcase name="hasFormat_A4Landscape">
  <assertThat testDocument="format/format_A4-Landscape.pdf">
    <hasFormat format="A4_LANDSCAPE" />     1
<testcase name="hasFormat_LetterPortrait">
  <assertThat testDocument="format/format_Letter-Portrait.pdf">
    <hasFormat format="LETTER_PORTRAIT" />  1

1 1

Constants exist for many popular formats.

You can also verify individual formats:

<testcase name="hasFormat_FreeFormat_1117x836_mm">
  <assertThat testDocument="format/physical-map-of-the-world-1999_1117x863mm.pdf">
    <hasFormat width="863.8" height="1117.6" unit="MILLIMETER" /> 1
<testcase name="hasFormat_FreeFormat_10x15_cm">
  <assertThat testDocument="format/format_Individual-10x15-cm.pdf">
    <hasFormat width="10.0" height="15.0" unit="CENTIMETER" />    1 

1 1

You can use the measurement units POINTS, MILLIMETER, CENTIMETER, INCH and DPI72. The units DPI72 and POINTS are equivalent. All units must be declared in the attribute unit="..".

The topic of different paper sizes and their dimensions in points, millimeters and inches is well documented at www.prepressure.com.

Tolerances of width and height are accepted when comparing expected values with actual values. The standard ISO 216 (http://en.wikipedia.org/wiki/Paper_size) specifies tolerances and also the popular standard DIN 476. PDFUnit uses the stricter tolerances of DIN 476 for all formats.

Documents with Multiple Formats

A document with pages of different sizes can also be checked for its formats:

<testcase name="hasFormat_DifferentFormatsOnDifferentPages">
  <assertThat testDocument="format/format_multiple-formats-on-individual-pages.pdf">
    <hasFormat format="A4_LANDSCAPE" on="FIRST_PAGE" />
    <hasFormat format="A5_PORTRAIT" onPage="3" />

The format tests can be restricted to individual pages or page ranges as described in chapter 13.2: “Page Selection”:

<testcase name="hasFormat_OnAnyPageBefore">
  <assertThat testDocument="format/format_multiple-formats-on-individual-pages.pdf">
    <hasFormat format="A4_LANDSCAPE" onAnyPageBefore="3" />
<testcase name="hasFormat_OnAllPagesAfter">
  <assertThat testDocument="format/format_multiple-formats-on-individual-pages.pdf">
    <hasFormat format="A5_PORTRAIT" onEveryPageAfter="2" />