On Windows 11, after upgrading from 6.1.1 to 6.2.0 (and 6.2.1), we've started getting this error:
System.InvalidOperationException
The font 'Courier New' cannot be resolved for predefined error font. Use another font name or fix your font resolver. See
https://docs.pdfsharp.net/link/migradoc ... g-6.2.html and
https://docs.pdfsharp.net/link/font-resolving.html for further information.
at MigraDoc.Rendering.DocumentRenderer.PredefinedFontsAndChars.CreateFont(String familyName, Double emSize, XFontStyleEx style, String propertyDescription)
at MigraDoc.Rendering.DocumentRenderer.PredefinedFontsAndChars.get_ErrorFont()
at MigraDoc.Rendering.DocumentRenderer.PredefinedFontsAndChars.CreateAllFixedFonts()
at MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely)
at MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages()
at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument()
I've tried implementing several different flavors of font resolver, to no avail - and honestly, it doesn't seem like that should be necessary, especially for a standard font like "Courier New".
Reverting to 6.1.1 fixes things.
This test reproduces the error:
Code:
[Fact]
public void CreateDoc_ShouldCreatePdfDocument()
{
var doc = new Document { Info = { Title = "Some title" } };
var section = doc.AddSection();
var par = section.AddParagraph("Some text");
par.Format.Font.Size = Unit.FromPoint(10);
par.Format.Font.Name = "Courier New";
par.Format.Font.Bold = true;
using var pdfDocument = new global::PdfSharp.Pdf.PdfDocument();
using var stream = new MemoryStream();
var renderer = new PdfDocumentRenderer
{
PdfDocument = pdfDocument,
Document = doc,
};
renderer.RenderDocument();
pdfDocument.Save(stream, true);
var pdfBytes = stream.ToArray();
pdfBytes.Should().NotBeNull();
}