I’m developing an application in c# using winforms and I need to print some documents like contracts, amortization tables and some other stuff, all based in predefined templates. Template’s structure aren’t that complex, just some tables, text formatting and two column pages. The goal is to print documents based on those templates with some data loaded dynamically. First I was thinking to achieve that using some PDF libraries like PDFSharp or iText but then I found out that there are other technologies like XPS or XSL-FO maybe suitable for my needs.
What are your recommendations guys? Any help would be appreciated.
How about doing office interop and just using Word templates?
The client would probably have to want to do this. The thing I like about it, is with bookmarks is pretty easy to replace data in the template with data from your application. It’s also convenient when some of the static text changes. You can just update the templates and distribute them, no recompiling. Also if the client wants to preview it in Word before printing that is somewhat automatic. There are some nitty gritty details about using interop but with C# 4.0 it certainly got a lot easier and is always a good skill to have.
On the downside if your templates are in a convenient location an ornery user could go in and modify things and break the reports. Also with tables if you have a lot of data, the standard documented method of adding a cell at a time can be pretty slow. Creating delimited text and then doing the text-to-table call is pretty fast but then you have to do all the formatting in code.
On the XPS side I did see a good overview video on pluralsight. It was part of the WPF course so I’m not sure how it translates to a winform app. I think you get to watch at least a couple of hours for free so it might be worth checking out if you want to get an overview of how XPS printing works.