0

I have used itext in Java to convert a HTML to PDF.

Now I want to test if the PDF generated by me is correct i.e the positions and contents all are correct and at correct positions.

Is there away to do the testing of my code?

Anuranjan
  • 134
  • 1
  • 1
  • 8
  • I want some automated mechanism so that there is no room for any error and also that requires least support intervention – Anuranjan Jul 03 '14 at 11:35
  • What would your reference be for "correctness"? Regardless, see this answer for how iText does it: http://stackoverflow.com/a/13703359/231316 – Chris Haas Jul 03 '14 at 13:08

1 Answers1

1

Basically, Your question is about validating itext output.

If You do not trust library for converting HTML to PDF, You probably do not trust reading raw PDF data as well. You can therefore use other libraries (PDF clown) for parsing PDF as a validation.

You have 2 approaches.

First one requires rasterization of PDF (GhostScript) and comparing to HTML. Indeed, the performance overhead is significant.

Second one parses the document format. I have gone into depth in my previous answer about searching for text inside PDF file. I have mentioned there searching for text as well as finding it's position on page.

I would suggest just simply avoid validating of output, unless You know something is wrong. These libraries are widely-used and well-tested.

Community
  • 1
  • 1
Gotcha
  • 392
  • 2
  • 10
  • If you look at the iText POM file (Java version), you'll see that we have a test framework that uses GhostScript. You can write your tests the same way we do inspired by the tests that we made available on SourceForge. – Bruno Lowagie Jul 03 '14 at 13:36