PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Fri Aug 29, 2025 11:33 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Aug 11, 2025 6:44 pm 
Offline

Joined: Mon Aug 11, 2025 6:16 pm
Posts: 1
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();
    }


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 11, 2025 8:45 pm 
Offline
User avatar

Joined: Thu Mar 06, 2025 10:43 am
Posts: 5
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Majestic-12 [Bot] and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group