3.19.  Number of PDF Elements

Overview

Not only the number of pages can be a test goal, also any kind of countable items in a PDF document, e.g. form fields and bookmarks. The following list shows the items that are countable and therefore testable:

<!-- Tags to count parts of a PDF: -->

<hasNumberOfActions                 />
<hasNumberOfBookmarks               />
<hasNumberOfDifferentImages         />   1
<hasNumberOfEmbeddedFiles           />
<hasNumberOfFields                  />
<hasNumberOfFonts identifiedBy=".."      (required)
/>
<hasNumberOfJavaScriptActions       />
<hasNumberOfLayers                  />
<hasNumberOfOCGs                    />
<hasNumberOfPages                   />   2
<hasNumberOfSignatures              />
<hasNumberOfVisibleImages           />   3

1 3

Tests for the number of images are described in chapter 3.13: “Images in PDF Documents”.

2

Tests for the number of pages are described in chapter 3.20: “Page Numbers as Objectives”.

Examples

Validating the number of items in PDF documents works identically for all items. So only two of them are shown as examples:

<testcase name="hasNumberOfFields">
  <assertThat testDocument="acrofields/simpleRegistrationForm.pdf">
    <hasNumberOfFields>4</hasNumberOfFields>
  </assertThat>
</testcase>
<testcase name="hasNumberOfBookmarks">
  <assertThat testDocument="bookmarks/manyBookmarks.pdf">
    <hasNumberOfBookmarks>19</hasNumberOfBookmarks>
  </assertThat>
</testcase>

All tests can be combined:

<testcase name="testHugeDocument_MultipleInvocation">
  <assertThat testDocument="performance/groovy_wiki-snapshot_1370.pdf">
    <hasNumberOfPages>1370</hasNumberOfPages>
    <hasNumberOfBookmarks>565</hasNumberOfBookmarks>
    <hasNumberOfActions>1896</hasNumberOfActions>
    <hasNumberOfEmbeddedFiles>0</hasNumberOfEmbeddedFiles>
  </assertThat>
</testcase>

Be careful, this test with a document containing 1370 pages takes about 10 seconds on a contemporary notebook. Separate the long-running test from the fast ones and start them with two ANT scripts.