Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Fonts in an Azure-Function

I try to get PdfSharp working in an Azure Function But I have some problems with fonts

 // Create a new PDF document
  PdfDocument document = new PdfDocument();
  document.Info.Title = "Created with PDFsharp";

  // Create an empty page
  PdfPage page = document.AddPage();

  // Get an XGraphics object for drawing
  XGraphics gfx = XGraphics.FromPdfPage(page);

  // Create a font
  XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

  // Draw the text
  gfx.DrawString("Hello, World!", font, XBrushes.Black,
    new XRect(0, 0, page.Width, page.Height),
    XStringFormats.Center);

This is also the code from the PDFSharp sample page... At the font line he gives me the following error...

Exception while executing function: Functions.PDFGenerationFunction. PdfSharp: Internal error. Font data could not retrieved.

Do I need to reference something special? Or is it just not possible to do this in an Azure function?

PDFSharp version --> "PDFsharp" : "1.32.3057"

And/Or another solution to generate a PDF document in an Azure Function...

like image 561
Sven Avatar asked Dec 19 '25 16:12

Sven


1 Answers

This is likely an issue with the sandbox that Azure Functions and webapps run in. Check out this list for known PDF libraries that will work in the sandbox. https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks

like image 198
Mike S Avatar answered Dec 22 '25 05:12

Mike S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!