Is Your PDF correct?

Automate your PDF test. Download test version

PDFUnit on the PDF Days Europe 2016

A successful conference has finished. For all who can't join it, the presentation is now available:

Automated PDF Testing with PDFUnit

Why should you test PDF documents?

These days telephone bills, insurance policies, official notifications and many types of contracts are delivered as PDF documents. They are the result of a process chain consisting of programs in various programming languages. Depending on the complexity of the documents to be produced, programming is not easy. Errors can arise at each step.

So you should verify:

  • Does an expected text lays inside the expected page region?
  • Is the text of a bar code the expected text?
  • Does the layout fulfill the requirements?
  • Is the PDF signed? When and by whom?
  • Do the embedded ZUGFeRD data have expected values?
  • Are the values of the embedded ZUGFeRD data correspond with the visible values?
  • Is a PDF conform with DIN 5008?

It should scare developers, project managers and CEO's that until now there is almost no way of repeatedly testing PDF documents. And even the options which are available are not used as frequently as they should be. Unfortunately, manual testing is widespread. It is expensive and prone to errors.

PDFUnit indirectly tests and verifies the process that creates your PDF.

Technical view

For your tests, it doesn't matter whether the PDF documents are created with a design tool, exported from MS-Word or Libre-Office or produced using an API. PDFUnit checks them all. PDFUnit is available as a Java API, a .NET API, an XML dialect and as a Perl module. All technologies are functionally identical. Furthermore, there is the application PDFUnit-Monitor that automatically monitors PDF documents in directories.

PDFUnit integrates well into JUnit or TestNG and can be used within ANT, Maven, Graddle or any other automation tool.

Please, contact us for any question: info(at)pdfunit.com

Example

See, how simple it is.

@Test
public void hasText_OnFirstPage_InRegion() throws Exception {
  String pdfUnderTest = "documentUnderTest.pdf";
  int leftX  =  17;  // in millimeter
  int upperY =  45;
  int width  =  80;
  int height =  50; 
  PageRegion addressRegion = new PageRegion(leftX, upperY, width, height);
  AssertThat.document(pdfUnderTest)
            .restrictedTo(FIRST_PAGE)
            .restrictedTo(addressRegion)
            .hasText()
            .containing("John Doe Ltd.")
  ; 
}

The same in Perl:

lives_ok {
 my $pdfUnderTest = "documentUnderTest.pdf";
    
 my $leftX  =   0;
 my $upperY =   0;
 my $width  = 210;
 my $height =  50;
 my $addressRegion = PageRegion->new($leftX, $upperY, $width, $height);
    
 AssertThat->document($pdfUnderTest)
           ->restrictedTo(FIRST_PAGE)
           ->restrictedTo($addressRegion)
           ->hasText()
           ->containing('John Doe Ltd.')
 ;
} 'hasText_OnFirstPage_InRegion';

The same in C#:

[TestMethod] 
public void hasContentOnFirstPage() 
{
  String pdfUnderTest = "documentUnderTest.pdf";
    
  int leftX  =   0;
  int upperY =   0;
  int width  = 210;
  int height =  50; 
  PageRegion region = new PageRegion(leftX, upperY, width, height);

  AssertThat.document(pdfUnderTest)
            .restrictedTo(Constants.FIRST_PAGE)
            .restrictedTo(region)
            .hasText()
            .containing("John Doe Ltd.")
  ;

The XML version of the same test:

<testcase name="hasText_OnFirstPage_InRegion">
  <assertThat testDocument="documentUnderTest.pdf">
    <hasText on="FIRST_PAGE" >
      <inRegion upperLeftX="0" upperLeftY="0" width="210" height="50" >
        <containing>John Doe Ltd.</containing>
      </inRegion>
    </hasText>
  </assertThat>
</testcase>

Downloads

The download page provides the current release, examples and detailed documentation.

Article in 'Java aktuell', 02-2015 (german only)

The german magazin 'Java aktuell' printed an introduction into PDFUnit. Download it here

License

You can try out PDFUnit without having to register. To use PDFUnit in a commercial context, you have to purchase a licence. For more information about licensing, see here.