I am using PDFSharp to dynamically generate PDF's in my web app. The web app works fine locally however, when I push the app to Azure (as a Web App), I get the following exception:
{"message":"An error has occurred.","exceptionMessage":"Internal error. Font data could not retrieved.","exceptionType":"System.InvalidOperationException","stackTrace":" at PdfSharp.Fonts.OpenType.FontData.CreateGdiFontImage(XFont font, XPdfFontOptions options)\r\n at PdfSharp.Fonts.OpenType.FontData..ctor(XFont font, XPdfFontOptions options)\r\n at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font, XPdfFontOptions options)\r\n at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font)\r\n at PdfSharp.Fonts.FontDescriptorStock.CreateDescriptor(XFont font)\r\n at PdfSharp.Drawing.XFont.get_Metrics()\r\n at PdfSharp.Drawing.XFont.Initialize()\r\n at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize)\r\n at Spiro.Services.OrderService.GetOrderLabel(Int32 id, Nullable`1 quantity)\r\n at Spiro.Web.Controllers.WebApi.V1.OrderController.GetOrderLabel(Int32 id, Nullable`1 quantity)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}
I create the text as follows:
var document = new PdfDocument();
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);
var font = new XFont("Calibri", 30);
gfx.DrawString(rows[i], font, XBrushes.Black,
new XPoint(XUnit.FromMillimeter(10),
XUnit.FromMillimeter(10)),
XStringFormats.TopLeft);
I can see that the Azure server has a bunch of fonts installed - I'm stuck as to what the problem is... Thank you for your help in advance.