PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
The font 'Courier New' cannot be resolved for predefined err https://forum.pdfsharp.net/viewtopic.php?f=2&t=4865 |
Page 1 of 1 |
Author: | smithkl42@gmail.com [ Mon Aug 11, 2025 6:44 pm ] |
Post subject: | The font 'Courier New' cannot be resolved for predefined err |
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(); } |
Author: | !!! [ Mon Aug 11, 2025 8:45 pm ] |
Post subject: | Re: The font 'Courier New' cannot be resolved for predefined |
smithkl42@gmail.com wrote: 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". Instead of sharing the unit test (that must fail), you could have shared your font resolvers for improvement.You create a program that can be used under Windows, MacOS, and Linux including Raspberry Pi. Where can Courier New be found on all these platforms? With version 6.1.1, you'll get the exception the first time that an error message is added to your document. And that may well happen on the computer of a customer, not a developer machine. BTW: I hope you noticed the two links in the error message you posted above. I hope you also noticed that you can change the error font if you use a font resolver that does not support Courier New. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |