Chapter 4. Comparing a Test PDF with a Reference

4.1.  Overview

Many tests follow the principle of comparing a newly created test document with a PDF document which has already been validated. Such tests are useful if the process that creates the PDF has to be changed, but the output should be the same.

Initialization

The instantiation of a reference document is done with the method and(..):

@Test
public void testInstantiationWithReference() throws Exception {
  String filenameTest = "documentUnderTest.pdf";
  String filenameReference = "reference.pdf";
  String passwordTest = "owner-password";
  
  AssertThat.document(filenameTest, passwordTest) 1
            .and(filenameReference)               2
  ;
}

1

If the test document is password protected, the second parameter is needed.

2

If the referenced document is not password protected, only the file name is needed. Otherwise a password has be used passed to the method.

Passwords are only used to open the documents. They do not influence the tests.

Overview

The following list gives a complete overview of all tests which compare two PDF files. Links after each tag refer to the chapter which describes it in detail.

// Methods to compare two PDF documents:

.haveSameAccessPermission()           4.12: “Comparing Permission” 
.haveSameAccessPermission(..)         4.12: “Comparing Permission” 
.haveSameAppearance()                 4.10: “Comparing Layout as Rendered Pages” 
.haveSameAuthor()                     4.5: “Comparing Document Properties” 
.haveSameBookmarks()                  4.3: “Comparing Bookmarks” 
.haveSameCreationDate()               4.4: “Comparing Date Values” 
.haveSameCreator()                    4.5: “Comparing Document Properties” 
.haveSameEmbeddedFiles(..)            4.2: “Comparing Attachments” 
.haveSameFieldsByName()               4.7: “Comparing Form Fields” 
.haveSameFieldsByValue()              4.7: “Comparing Form Fields” 
.haveSameFormat()                     4.6: “Comparing Format” 
.haveSameImages()                     4.8: “Comparing Images” 
.haveSameJavaScript()                 4.17: “More Comparisons” 
.haveSameKeywords()                   4.17: “More Comparisons” 
.haveSameLanguageInfo()               4.17: “More Comparisons” 
.haveSameLayerNames()                 4.17: “More Comparisons” 
.haveSameModificationDate()           4.4: “Comparing Date Values” 
.haveSameNamedDestinations()          4.11: “Comparing Named Destinations” 
.haveSameNumberOfBookmarks()          4.3: “Comparing Bookmarks”       
.haveSameNumberOfEmbeddedFiles()      4.2: “Comparing Attachments” 
.haveSameNumberOfFields()             4.7: “Comparing Form Fields” 
.haveSameNumberOfImages()             4.8: “Comparing Images” 
.haveSameNumberOfLayers()             4.13: “Comparing Quantities of PDF Elements” 
.haveSameNumberOfNamedDestinations()  4.11: “Comparing Named Destinations” 
.haveSameNumberOfPages()              4.13: “Comparing Quantities of PDF Elements” 

...  continued
... continuation:

.haveSameProducer()                   4.5: “Comparing Document Properties” 
.haveSameProperties()                 4.5: “Comparing Document Properties” 
.haveSameProperty(..)                 4.5: “Comparing Document Properties” 
.haveSameSubject()                    4.5: “Comparing Document Properties” 
.haveSameTaggingInfo()                4.17: “More Comparisons” 
.haveSameText()                       4.14: “Comparing Text” 
.haveSameTitle()                      4.5: “Comparing Document Properties” 
.haveSameXFAData()                    4.15: “Comparing XFA Data” 
.haveSameXMPData()                    4.16: “Comparing XMP Data”