PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jul 20, 2024 10:21 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 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 Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
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  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 48 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group