Wednesday, September 7, 2016

How to unit test PDF creation in .Net

This is a quick recipe to set up in an easy way unit testing for PDF documents in .Net.

The idea, since it wouldn't be possible to verify the layout of a PDF, is to check its text contents.

In order to do so we can use the iTextSharp library. This library enables creating and editing PDF documents. It's commercial but is free for this kind of usage, as long as you don't make it part of a commercial solution.

First of all you should install iTextSharp Nuget package:

PM> Install-Package iTextSharp

Then you can use the following simple method to check if a given text is present in a PDF binary:

No comments:

Post a Comment