3.19.  Number of PDF Elements


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”.


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


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">
<testcase name="hasNumberOfBookmarks">
  <assertThat testDocument="bookmarks/manyBookmarks.pdf">

All tests can be combined:

<testcase name="testHugeDocument_MultipleInvocation">
  <assertThat testDocument="performance/groovy_wiki-snapshot_1370.pdf">

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.