4

I'm doing some automated regression testing on a web application using Rational Functional Tester with Java. I need to test some PDF files produced by that application, comparing them with a "base" PDf file that has been manually validated. The testing is content-based, meaning that little differencies in disposition on page are tolerated. Some content like dates or purchase IDs are variable, and should not be considered errors, so I need comparing with regexps or similar. Image matching with adjustable tolerance would be a great plus, for comparing QR codes and other bar codes.

When an error occours, I want a screenshot with base page and the faulty one.

Actually I built a wrapper around this library to suit my requirements

http://www.inetsoftware.de/other-products/pdf-content-comparer

It works quite good for PDF-1.3, but seems like the library poorly supports files in PDF-1.4 format. It's not possible to change the output format of the web app, and regression bugs are quite common in the prints.

Any PDF comparer library to suggest? Preferred language is Java, as RFT is Java based, but anything's fine.

2
  • Allessandro, did you find the tool of choice for your need? Do you still use INET PDFC? It's very expensive. I'm also looking for mass pdf regression testing tool (content-aware, command line, java tool (api)). What do you use?
    – user3105
    Commented Sep 20, 2012 at 7:36
  • I'm still using INET PDFC, but an older free version. You can download now a 30 days free trial. It's the best tool I've found and I think it's not too expensive. Commented Sep 20, 2012 at 11:08

4 Answers 4

3

I do not know any PDF library that had satisfying results. My way is currently to convert PDF to text and work from there. A-PDF Text Extractor is my tool of choice here.

1
  • 1
    I also do the same using Apache PDFBox for some content, but I need a "visual" check of the pages. Text may be scrambled or paragraphs repeated more than once on different parts of the document. Commented Aug 6, 2012 at 8:02
1

While not precisely a library in the past I have used Beyond Compare to do this sort of comparisons. It supports being scripted. I essentially created the script which drove the how I wanted the comparisons performed and then I executed the app from my test harness. It does look like the company that put out your library recently released a 2.0 beta. Have you tried that?

3
  • The "Beyond Compare" tools does not seem to support PDF files. Binary content of files is different, as some dates and IDs change, I'm looking for some tool that also support some kind of check on how the pages are formatted, if paragraphs are missing and so. I tryed the 2.0.60 beta of INET PDFC but it's broken. I already opened a ticket to their support service. Stable 1.10 release has some defects and is not working very well. Commented Aug 6, 2012 at 12:55
  • Allessandro - I am not sure what gave you that idea. I just used it on some the other day. Take a look at the mention here: scootersoftware.com/moreinfo.php?zz=moreinfo_compare The when comparing a pdf it does a compare on the underlying text in the documents. I do know you can customize rule sets to specify white space parameters and such.
    – Dan Snell
    Commented Aug 6, 2012 at 16:27
  • Maybe I was not clear enough in my question. "Beyond Compare" supports text extraction from PDF, but what happens if the text is OK but there isn't the table containing it, and in image is missing? What if the text is OK but there's a huge hole in the middle of the page, pushing the text at the bottom? I need also a visual comparison. INET PDFC makes screenshots of the pages and highlights the structural (and of course, text) differencies, but It does not work on a lot of files :-/ Commented Aug 7, 2012 at 11:46
1

I know your post is quite old, but there is a library for testing PDF content: https://github.com/codeborne/pdf-test

Very easy to use. Just write on assert like this:

PDF pdf = new PDF(new File("src/test/resources/50quickideas.pdf"));
assertThat(pdf, containsText("50 Quick Ideas to Improve your User Stories"));
0

You can convert your PDF result file and the corresponding base file to images and then do a comparison bits by bits on the images. You can build some kind of tolerance for instance less than 2% in gray scale value to handle the bar codes.

For areas that are variable such as dates or purchase IDS, you could black them out in the resulting images before doing the image comparison.

To convert PDF to images, you can use our java library jPDFImages , you would get a buffered image for each page.

Contact us if you need help. This is an interesting problem as we're considering developing a PDF comparison library soon.

1
  • The blacking out of variable areas would be overwhelming, (10 different type of documents, each about 50-70 pages, that may vary every 2 months) so I prefer to stick to my actual implementation. I bookmarked your site though, looking forward for a full comparison library =) Commented Aug 24, 2012 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.