1
votes

VS2017 .NET 4.7

I have written a Web App that creates a PDF, the only related nuget package I have installed is:

PDFsharp-MigrDoc-GDI v1.32.4334

It works fine locally on my development machine.

But when I published it to Azure I get the error:

Font data could not be retrieved.

I have found that I need to include the fonts I use as resources in the code, as they may not be present on Azure.

I have also found this:

https://github.com/empira/PDFsharp/blob/master/src/PdfSharp/Fonts/PlatformFontResolver.cs

But I am starting to get confused. Which packages do I need? Do I need PDFsharp, MigraDoc or both?

Any help pointing me in the right direction would help. OR. A simple example "Hello World" PDF (using PDFsharpe/MigraDoc) solution which works on a Azure Web App.

Thanks

1

1 Answers

2
votes

MigraDoc is a set of APIs to create documents.

PDFsharp is a library that creates PDF files.

If you use the MigraDoc API, you will need MigraDoc and PDFsharp. If you only use the PDFsharp API, then you only need the package that includes PDFsharp, but not MigraDoc.

To use IFontResolver, you need the WPF build version 1.50 or higher.

With MigraDoc:
https://www.nuget.org/packages/PDFsharp-MigraDoc-wpf/1.50.4845-RC2a

Just PDFsharp:
https://www.nuget.org/packages/PDFsharp-wpf/1.50.4845-RC2a

EZFontResolver may help to simplify using IFontResolver:
https://forum.pdfsharp.net/viewtopic.php?f=8&t=3244

The PDFsharp samples include a FontResolver sample that loads fonts from resources:
https://github.com/empira/PDFsharp-samples