How to convert XHTML to PDF in C#


In this blog post I will illustrate how you could convert an XHTML page into PDF using the flying-saucer library. This is a Java library so we need to first step would be to convert it to a .NET assembly.

I will use the IKVM.NET Bytecode Compiler (ikvmc.exe) for this purpose. So go ahead and download both the flying-saucer library and the IKVM project. Then run the following command:

This will generate the CoreRenderer.dll assembly which could be used. And finally we would create an application which would use it inside a console application:sourcecode395858614


One last step is to ensure that you have referenced the following assemblies:


Those assemblies are part of the IKVM project and have dependencies on many other assemblies that are included with it. So the final folder should contain all those:


And that’s pretty much all. When you run the console application it should generate the output PDF file.

Leave a comment

Your email address will not be published. Required fields are marked *