3.8.  DIN 5008

Overview

DIN 5008 defines rules for formating letters and also some rules for text in letters. PDFUnit can check for compliance with these rules. A lot of rules are defined by the standard as a recommendation only, so companies have to select which rules they want to follow. The selected rules must be written into an Excel file. PDFUnit reads this Excel file and applies all the rules to all related PDF documents.

The following methods can be used to validate documents against DIN 5008:

// Methods to validate DIN 5008 constraints:
.compliesWith().din5008FormA()
.compliesWith().din5008FormB()

Information about DIN 5008 can be found online at https://en.wikipedia.org/wiki/DIN_5008. Chapter 3.10: “Excel Files for Validation Constraints” describes how the rules must be written in Excel files.

Example - Validate a Single Document

In the next example only the PDF document is given to the testing method, not the Excel file with the rules. The name and the directory of the Excel file are instead declared in the config file pdfunit.config:

#
#############################################################################
#
# Definition of PDF validation files.
#
#############################################################################
file.din5008.forma = src/main/resources/din5008/ValidationRules-DIN5008-FormA.xls
file.din5008.formb = src/main/resources/din5008/ValidationRules-DIN5008-FormB.xls

The directory can be either an absolute or a relative path.

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

  AssertThat.document(filename)
            .compliesWith()
            .din5008FormB()
  ;
}

If multiple Excel files exist, the above syntax is not enough. The name of the Excel file has to be given to the testing method:

@Test
public void din5008FormB() throws Exception {
  String filename = "documentUnderTest.pdf";
  String rulesAsExcelFile = PATH_TO_RULES + "din5008-formB_letter-portrait.xls";
  PDFValidationConstraints excelRules = new PDFValidationConstraints(rulesAsExcelFile);

  AssertThat.document(filename)
            .compliesWith()
            .constraints(excelRules)
  ;
}

Example - Validate Each Document in a Folder

The last two examples can be used with a folder instead of a single document. Then each PDF file in the folder will be validated:

@Test
public void compliesWithDin5008BInFolder() throws Exception {
  String filename = "documentUnderTest.pdf";
  File folderWithPDF = new File(folderName);

  AssertThat.eachDocument()
            .inFolder(folderWithPDF)
            .compliesWith()
            .din5008FormB()
  ;
}