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