13.8.  Format Units - Points and Millimeters

Tests with page regions require width and height values. These values can be expressed in either millimeters or points. The following constants exist for these units:

// Predefined format units:


When points are converted into millimeters, 72 DPI (Dots per Inch) are used. Measurement units play a role in examples such as the following:

Format Units

public void hasField_Width() throws Exception {
  String filename = "documentUnderTest.pdf";
  String fieldname = "Title of 'someField'"; 
  int allowedDeltaForMillis = 2;
  int allowedDeltaForPoints = 0;
            .withWidth(450) // default is POINTS
            .withWidth(450, POINTS, allowedDeltaForPoints)
            .withWidth(159, MILLIMETERS, allowedDeltaForMillis)

In the previous example, 'width' refers to width as the internal property of the acro field. Since this is expressed in the unit points, PDFUnit takes the values for the methods withWidth(..) and withHeight(..) by default in points. To prevent rounding errors when converting points into millimeters, the third parameter of those methods determines the allowable difference between the expected size and the actual size.

Example - Page Format

public void hasHugeFormat() throws Exception {
  String filename = "documentUnderTest.pdf";
  int heightMM = 1117;
  int widthMM = 863;
  DocumentFormat formatMM = new DocumentFormatMillis(widthMM, heightMM);

When page formats are created, the constants MILLIMETERS and POINTS cannot be used. Use the classes DocumentFormatMillis and DocumentFormatPoints instead.

Example - Error messages

Error messages print both the original unit and millimeters. For example, if the width in the last example had been set to 111 POINTS, PDFUnit would have shown the following error message:

Wrong page format in 'physical-map-of-the-world-1999_1117x863mm.pdf' on page 1. 
Expected: 'height=1117.60, width=39.16 (as 'mm', converted from unit 'points')', 
but was:  'height=1117.60, width=863.60 (as 'mm')'.