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: compare text with reference document
#
lives_ok {
  my $filenameTest   = "$resources_dir/master/compareToMaster_encrypted.pdf";
  my $filenameMaster = "$resources_dir/master/compareToMaster.pdf";
  my $userPassword   = 'user-password';
  AssertThat->document($filenameTest, $userPassword)   1
            ->and($filenameMaster)                     2
            ->restrictedTo(FIRST_PAGE)
            ->haveSameText()
  ;
} "compare text with reference document";

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.

The following list gives a complete overview of all tests which compare two PDF files. The details are described in the manual of PDFUnit-Java to avoid redundant documentation. Follow the link to the PDFUnit-Java manual: http://www.pdfunit.com/en/documentation/java/.

# Methods to compare two PDF documents:
# 
# The detailed descriptions can be found in the manual of PDFUnit-Java (to avoid redundancy).
# The names of the methods are exactly the same.
#
# see   http://www.pdfunit.com/en/documentation/java/ 
#  

->haveSameAccessPermission()    
->haveSameAccessPermission(..)  
->haveSameAppearance()          
->haveSameAuthor()              
->haveSameBookmarks()                 
->haveSameCreationDate()              
->haveSameCreator()             
->haveSameEmbeddedFiles(..)     
->haveSameFieldsByName()              
->haveSameFieldsByValue()             
->haveSameFormat()                    
->haveSameImages()                    
->haveSameJavaScript()                
->haveSameKeywords()                  

...  continued
... continuation:

->haveSameLanguageInfo()              
->haveSameLayerNames()                
->haveSameModificationDate()          
->haveSameNamedDestinations()     
->haveSameNumberOfBookmarks()               
->haveSameNumberOfEmbeddedFiles() 
->haveSameNumberOfFields()            
->haveSameNumberOfImages()            
->haveSameNumberOfLayers()            
->haveSameNumberOfNamedDestinations()
->haveSameNumberOfPages()             
->haveSameProducer()                  
->haveSameProperties()                
->haveSameProperty(..)                
->haveSameSubject()                   
->haveSameTaggingInfo()               
->haveSameText()                      
->haveSameTitle()                     
->haveSameXFAData()                   
->haveSameXMPData()                   

Once again the link to the PDFUnit-Java manual: http://www.pdfunit.com/en/documentation/java/.