PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Fri May 16, 2025 5:46 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  [ 5 posts ] 
Author Message
 Post subject: Macos font exception
PostPosted: Sat Jun 29, 2024 3:56 pm 
Offline

Joined: Sat Jun 29, 2024 3:29 pm
Posts: 2
Hi,

I'm currently developing on a m1 mac and have created a console application that targets .net 8 and have added PDFsharp 6.1.0 pacakage

I have added a snippet to from the sample code repo

Code:
        var document = new PdfDocument();
        document.Info.Title = "Created with PDFsharp";
        document.Info.Subject = "Just a simple Hello-World program.";

        var page = document.AddPage();

        var gfx = XGraphics.FromPdfPage(page);

        var width = page.Width.Point;
        var height = page.Height.Point;
        gfx.DrawLine(XPens.Red, 0, 0, width, height);
        gfx.DrawLine(XPens.Red, width, 0, 0, height);

        var r = width / 5;
        gfx.DrawEllipse(new XPen(XColors.Red, 1.5), XBrushes.White,
            new XRect(width / 2 - r, height / 2 - r, 2 * r, 2 * r));

        var font = new XFont("Times New Roman", 20, XFontStyleEx.BoldItalic);
        gfx.DrawString("Hello, PDFsharp!", font, XBrushes.Black,
            new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center);
        var filename = PdfFileUtility.GetTempPdfFullFileName("samples/HelloWorldSample");
        document.Save(filename);


I am getting the following exception when the code attempts to create the font. From the docs the font should work on platforms other than windows.
Quote:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
2024-06-29T15:45:08.650162924Z at PdfSharp.Fonts.OpenType.OpenTypeFontFace.CetOrCreateFrom(XFontSource fontSource)
2024-06-29T15:45:08.650168799Z at PdfSharp.Drawing.XGlyphTypeface..ctor(String key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations)
2024-06-29T15:45:08.650170299Z at PdfSharp.Drawing.XGlyphTypeface.GetOrCreateFrom(String familyName, FontResolvingOptions fontResolvingOptions)
2024-06-29T15:45:08.650171424Z at PdfSharp.Drawing.XFont.Initialize()
2024-06-29T15:45:08.650172466Z at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyleEx style, XPdfFontOptions pdfOptions)
2024-06-29T15:45:08.650173466Z at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyleEx style)



Can someone point me in the right direction?
Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Macos font exception
PostPosted: Sat Jun 29, 2024 9:01 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1044
Location: CCAA
gravy wrote:
From the docs the font should work on platforms other than windows.

From docs, this font should work under Windows and Linux, but not under MacOS.

Write a FontResolver that loads the font for use on Mac.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: Macos font exception
PostPosted: Sat Jun 29, 2024 9:15 pm 
Offline

Joined: Sat Jun 29, 2024 3:29 pm
Posts: 2
Thank you for clarifying.

Keep up the good work team!


Top
 Profile  
Reply with quote  
 Post subject: Re: Macos font exception
PostPosted: Wed Dec 18, 2024 7:30 pm 
Offline

Joined: Wed Dec 18, 2024 7:28 pm
Posts: 1
Quote:
2024-06-29T15:45:08.650162924Z at PdfSharp.Fonts.OpenType.OpenTypeFontFace.CetOrCreateFrom(XFontSource fontSource)

is that a typo?
I also got the same error on mac so that's what took me here :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Macos font exception
PostPosted: Thu Dec 19, 2024 10:24 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3128
Location: Cologne, Germany
pipja wrote:
Quote:
2024-06-29T15:45:08.650162924Z at PdfSharp.Fonts.OpenType.OpenTypeFontFace.CetOrCreateFrom(XFontSource fontSource)

is that a typo?
It is a typo. Fixed with next release. Thanks for the feedback.


pipja wrote:
I also got the same error on mac so that's what took me here :)
Do you get that error with PDFsharp 6.2.0 Preview 2?
There should be a different message with Preview 2, but we have no Mac for tests.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Baidu [Spider] and 28 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