Combining PDF Files Swiftly with PDFsharp

For one of my applications I had a simple task: the business needed an easy way to download all PDF files we create in various places inside our application. Offering them one single button who combines all those different files into one big PDF looked like a good idea. Little did I know about all the obstacles I had to overcome to get it done.

There are many libraries to work with PDF files. However, the current format is not supported by all and some libraries only work when you install additional software. As if this would not already be limiting enough, we also needed a license that allowed the usage in closed source software.

After many prototypes I settled with PDFsharp in a preview version. Here is a minimalistic example you can use to combine PDF files:

I took a calculated risk by using a preview version of this library. PDFsharp is encapsulated in a PdfHelper class, what allows us to change the implementation should a problem arise. We have automated tests to verify the functionality and can reuse them to check if the next regular version can do what we need. I strongly suggest you do something similar in your application. Not only when you use a preview release, but with all libraries. It’s not complicated and can be done without much effort.

 

Conclusion

Even widely used formats like PDF can have many features most libraries are unable to handle. Minimalistic prototypes can help you to find them quickly and without much effort.
 

2 thoughts on “Combining PDF Files Swiftly with PDFsharp”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.