Skip to content

derKrischan/jpdftest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JPdfTest

Maven Central CircleCI

This is a small library that will eventually be extended to test PDF contents programmatically. The focus is not on a per pixel comparison of images but to deliver some asserters to assure that some specific text/image is located in a certain area.

Table of contents

Design principles

The library is designed after the principles of fluent assertions. Every assertion returns the current or a new asserter. This is useful for improved test readability.

An example might be:

PdfAssertions.assertThat("myDocument.pdf")
	.pageCount().isBetween(41, 42)
	.page(1).textInRegion(MetricRectangle.create(120, 23, 39, 10)).chomp().matches("Hello world")
	.page(2).containsImage("resources/my_diagram.png")
	.document().author().isNotBlank().matches("Jon Doe")
	.document().producer().startsWith("LibreOffice");

Asserters may be used to traverse from documents to single pages and back to the whole document.

Features

  • Assert that a PDF document contains a specified text
  • Assert that a specified text is in a certain region
  • Verify PDF document page count
  • Assert that a specific image is embedded at a certain page
  • Assert that a specific image is in a certain area of a page
  • Assert that a PDF document is compliant to PDF/A-1b standard
  • Check the author of a PDF document
  • Check the creator of a PDF document
  • Check the subject of a PDF document
  • Check the title of a PDF document
  • Check the producer of a PDF document
  • Check the creation date of a PDF document
  • Check the document version
  • Assert page/document orientation
  • Assert page/document size
  • Load encrypted PDFs

Tech

  • The project uses PdfBox which tries to create a font cache in system temp directory. In case the user has no write access for that directory, an error occurs. In order to specify the font cache directory use the property "pdfbox.fontcache" via command line. E.g. :

    java -Dpdfbox.fontcache=path/to/cache ...

About

Test PDFs with Java programmatically instead of image comparison.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages