Chapter 10.  Best Practices

10.1.  Does Content Fit in Predefined Form Fields

Initial Situation

A PDF document is created using a document template with empty fields as place holders for text, e.g. the address of a customer in an advertising letter. At runtime the fields are filled with text.

Problem

The text could be larger than the available size of the field.

Solution Approach

PDFUnit provides a tag to detect text overflow.

Solution

<testcase name="noTextOverflow_AllFields">
  <assertThat testDocument="acrofields/fieldsWithAttributes.pdf">
    <hasFields>
      <allWithoutTextOverflow />
    </hasFields>
  </assertThat>
</testcase>

A similar test can be done with one field:

<testcase name="noTextOverflow_Field_AlignLeft">
  <assertThat testDocument="acrofields/fieldSizeAndText.pdf">
    <hasField withName="Textfield, text inside, align left:" >
      <withoutTextOverflow />
    </hasField>
  </assertThat>
</testcase>

Chapter 3.11: “Form Fields - Text Overflow” describes this subject in detail.