3.36.  Version Info

Overview

Sometimes, generated PDF documents need to have a particular version number before they can be processed in a workflow. That can be tested with the following methods:

// Simple tests:
.hasVersion().matching(..) 

// Tests for version ranges:
.hasVersion().greaterThan(..) 
.hasVersion().lessThan(..)

One Distinct Version

For popular PDF versions constants can be used:

// Constants for PDF versions:

com.pdfunit.Constants.PDFVERSION_11
com.pdfunit.Constants.PDFVERSION_12
com.pdfunit.Constants.PDFVERSION_13
com.pdfunit.Constants.PDFVERSION_14
com.pdfunit.Constants.PDFVERSION_15
com.pdfunit.Constants.PDFVERSION_16
com.pdfunit.Constants.PDFVERSION_17

Here an example to check for version 1.4

@Test
public void hasVersion_v14() throws Exception {
  String filename = "documentUnderTest.pdf";

  AssertThat.document(filename)
            .hasVersion()
            .matching(PDFVERSION_14)
  ;
}

Ranges of Versions

The existing constants can be used to verify version ranges:

@Test
public void hasVersion_GreaterThanLessThan() throws Exception {
  String filename = "documentUnderTest.pdf";
  
  AssertThat.document(filename)
            .hasVersion()
            .greaterThan(PDFVERSION_13) 1
            .lessThan(PDFVERSION_17)    2
  ;
}

1 2

Upper and lower limit values are exclusive.

Also, upcoming versions can be tested. The expected version must be given as a string of the format "%1.1f".

@Test
public void hasVersion_LessThanFutureVersion() throws Exception {
  String filename = "documentUnderTest.pdf";
  PDFVersion futureVersion = PDFVersion.withValue("2.0");
  
  AssertThat.document(filename)
            .hasVersion()
            .lessThan(futureVersion)
  ;
}