Note on PDFSharp library and ASP.NET web applications running on Azure Websites

Posted: (EET/GMT+2)

 

The open-source PDFSharp library is one of the freely available PDF creation components for the .NET platform. I'm using this library in several client projects, and it is working well, including in ASP.NET web applications.

However, using this library in Azure applications (as Web Apps) isn't always trivial. Instead, when using the PDFSharp library in your ASP.NET applications hosted on Azure, you might receive errors (exceptions) while working with the library. For instance, if you try to specify the font to use with the XFont class, you might get various error messages on Azure.

The Internet seems scarce on these kinds of errors, so I'm hoping to help fellow .NET developers running into similar issues with this post.

Now, the solution to these kinds of Azure related problems is simple: you need to use the correct PDFSharp library version. When you download the source code from CodePlex, you have the option for four different projects:

  • PdfSharp.csproj
  • PdfSharp-ag.csproj
  • PdfSharp-Hybrid.csproj
  • PdfSharp-WPF.csproj

Of these, the PdfSharp.csproj project is the one you should use by default. However, on Azure, only the PdfSharp-WPF.csproj library works, and this is the one you must use.

The programming interfaces are the same in all of these projects, but they use slightly different rendering techniques and also reference different assemblies along the way.

So, on Azure, use the WPF version of the PdfSharp library.

Merry Christmas!

Keywords: How to get PDFSharp to run on Azure; Error when using PDFSharp in Azure website